Skip to content
Tcl Source Code History Of Ticket 3362446fffffffff
Login

History Of Ticket 3362446fffffffff

Artifacts Associated With Ticket 3362446fffffffff

  1. Ticket change [a1ab8022d8] (rid 109766) by apnadkarni on 2011-07-11 04:35:05:

    1. assignee initialized to: "kennykb"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Use of the [registry keys] command fails under some circumstances on 8.5/8.6. This failure was not present in 8.4
      
      With 8.5
      % package require Tcl
      8.5.9
      % package require registry
      1.2.1
      % registry keys {HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog}
      unable to enumerate subkeys of "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog": More data is available.
      
      With 8.6, identical failure
      (tcl) 49 % package require Tcl
      8.6b1.2
      (tcl) 50 % package require registry
      1.3
      (tcl) 51 % registry keys {HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog}
      unable to enumerate subkeys of "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog": More data is available.
      
      With 8.4, this failure does not happen
      (tools) 1 % package require Tcl
      8.4
      (tools) 2 % package require registry
      1.1.3
      (tools) 3 % registry keys {HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog}
      Application {Internet Explorer} ODiag OSession Security System
      
      Logging bug as placeholder, Will follow up with additional info/trace
      
      /Ashok
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "apnadkarni"
    10. subsystem initialized to: "32. registry Package"
    11. title initialized to: "registry keys command fails with 8.5/8.6"
    12. type initialized to: "Bug"
  2. Ticket change [8b2d76a553] (rid 127518) by apnadkarni on 2011-07-11 14:07:44:

    1. icomment:
      Tracing through the code, the failure is in tclWinReg.c:GetKeyNames. The code calls RegQueryInfoKey to get number of keys and max length, allocates a buffer and iterates through the number of keys.
      
      There are several problems in this function:
      
      - race condition - the max length AND/OR number of keys can change during the iteration (if another thread/process modified/adds/deletes a key), causing the function to fail with either ERROR_MORE_DATA or ERROR_NO_MORE_ITEMS
      - There is a memory leak in case of errors
      - There is buffer overflow, I believe, if the code is compiled without _UNICODE defined (this may not matter anymore). The call to Tcl_WinTCharToUtf should use sizeof(TCHAR), not sizeof(WCHAR) I believe.
      
      Ironially enough, none of the above is the cause of the observed failure. The apparent reason is that RegQueryInfoKey does not always return the correct information when the Unicode version is used and the original key was stored using a MBCS call (this is just scuttlebutt but seems to match the circumstantial evidence). So the max length assumed by the function is in fact too small. I verified this in Visual Studio - the "Internet Explorer" key is 17 chars, but the returned max by RegQueryInfoKey is only 12. This is really then an MS bug, but their position is that RegQueryInfoKey return values cannot be relied upon and the sample iterative method in the sdk should be followed.
      
      Patch to follow...
      
      /Ashok
      
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. username: "apnadkarni"
  3. Ticket change [dc2827b027] (rid 108091) by apnadkarni on 2011-07-11 15:29:56:

    1. icomment:
      Patch is attached. Replaces the GetKeyName() function in win/tclWinReg.c. Tested against 8.6 head registry.test, all pass except 16 tests skipped (english/nonportable)
      
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. username: "apnadkarni"
  4. Add attachment "getkeynames.c" [4e56da7a3a] (rid 127211) by apnadkarni on 2011-07-11 15:31:17.

  5. Ticket change [90743fcff5] (rid 120454) by apnadkarni on 2011-07-11 15:31:18:

    1. icomment:
      
      
      File Added - 417741: getkeynames.c
      
      
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. username: "apnadkarni"
  6. Ticket change [ebfd3d2659] (rid 103633) by apnadkarni on 2011-07-11 15:33:08:

    1. icomment:
      (Sigh - SF seems to have thrown my previous patch update into a bitbucket somewhere, reattaching)
      
      Added patch - getkeynames.c - replace GetKeyNames in tclWinReg.c with the corresponding function in attached getkeynames.c file. Tested registry.test against 8.6 head.
      
      /Ashok
      
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. username: "apnadkarni"
  7. Ticket change [5488668351] (rid 93965) by mistachkin on 2011-07-11 16:45:20:

    1. icomment:
      
      
      File Added - 417746: winReg.diff
      
      
      
    2. login: "mistachkin"
    3. mimetype: "text/plain"
    4. username: "mistachkin"
  8. Ticket change [b1a7b4ead9] (rid 98181) by mistachkin on 2011-07-11 16:45:38:

    1. icomment:
      Thanks for the patch.  I'm wondering if something a bit more minimal would work in your case?  Could you try that attached patch and see if the issue persists?
      
      
      
    2. login: "mistachkin"
    3. mimetype: "text/plain"
    4. username: "mistachkin"
  9. Ticket change [47e52a3744] (rid 99786) by mistachkin on 2011-07-11 17:18:37:

    1. icomment:
      Attaching a more robust patch that fixes the Tcl_Obj leak as well.
      
      
    2. login: "mistachkin"
    3. mimetype: "text/plain"
    4. username: "mistachkin"
  10. Ticket change [c8fdc83918] (rid 122206) by mistachkin on 2011-07-11 17:18:45:

    1. icomment:
      
      
      File Deleted - 417746: 
      
      
      
    2. login: "mistachkin"
    3. mimetype: "text/plain"
    4. username: "mistachkin"
  11. Add attachment "winReg_v2.diff" [dbb15ebbc0] (rid 108003) by mistachkin on 2011-07-11 17:19:05.

  12. Ticket change [6d5a1a8bc6] (rid 128681) by mistachkin on 2011-07-11 17:19:05:

    1. icomment:
      
      
      File Added - 417748: winReg_v2.diff
      
      
      
    2. login: "mistachkin"
    3. mimetype: "text/plain"
    4. username: "mistachkin"
  13. Ticket change [0976c3da3b] (rid 113657) by apnadkarni on 2011-07-11 18:46:09:

    1. icomment:
      I won't get a hold of the failing machine again until tomorrow so I will try it then.
      
      Also, winReg_v2.diff does not handle the race condition when one of the keys is deleted. In this case, the command currently simply fails, whereas it should return a valid key list (either including or exculding the deleted key). It is akin to [glob] failing because someone deleted a file at the same time.
      
      Personal opinion, after making changes similar to yours, and then adding the handling of ERROR_NO_MORE_ITEMS to avoid the race, I thought it cleaner to rewrite the function, although I do understand the philosophy behind minimizing changes. Also, Tcl does MAX_PATH stack allocations in many places so a stack var of 257 saves unnecessary allocations.
      
      It's of course your call! I'll let you know tomorrow once I get hold of the failing system. I don't see why it would not work
      
      /Ashok
      
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. username: "apnadkarni"
  14. Ticket change [3df8824ee0] (rid 121188) by mistachkin on 2011-07-12 03:08:47:

    1. icomment:
      If these race conditions are truly a serious problem, perhaps other parts of tclWinReg.c need to be rewritten as well?  For example, I see several other calls to RegQueryInfoKey.
      
      
    2. login: "mistachkin"
    3. mimetype: "text/plain"
    4. username: "mistachkin"
  15. Ticket change [6d32a2c57a] (rid 128649) by apnadkarni on 2011-07-12 09:08:40:

    1. icomment:
      I dunno about serious but I hate it when operations fail for no apparent reason. The glob example I gave I think illustrates the point - you don't want glob failing because someone deletes/renames a file in the glob target. Of course, registry enum is likely to be far less common than globbing files but still...
      
      There are two other calls - to delete a key (tree) and enumerate values. The first I don't think needs fixing because when deleting a tree, the caller must always expect failure modes caused by other processes. The latter case probably does need fixing (but not the same fix since the value names are not limited to just 256 bytes.
      
      If you want, I can look at producing a patch for that as well.
      
      /Ashok
      
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. username: "apnadkarni"
  16. Ticket change [59c62499f1] (rid 118025) by apnadkarni on 2011-08-25 22:31:34:

    1. assignee changed to: "mistachkin"
  17. Ticket change [3cf94bb38a] (rid 121007) by apnadkarni on 2012-05-02 23:31:50:

    1. priority changed to: "7 High"
  18. Ticket change [4d6a4b6d77] (rid 127048) by nijtmans on 2012-06-19 18:59:32:

    1. icomment:
      > - There is buffer overflow, I believe, if the code is compiled without
      > _UNICODE defined (this may not matter anymore). The call to
      > Tcl_WinTCharToUtf should use sizeof(TCHAR), not sizeof(WCHAR) I believe.
      
      Good catch! That should be fixed now in trunk.
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  19. Ticket change [78f21a9670] (rid 90041) by nijtmans on 2012-06-19 20:22:20:

    1. icomment:
      See:
      http://msdn.microsoft.com/en-us/library/windows/desktop/ms724862%28v=vs.85%29.aspx
      
      This recommends just calling RegEnumKeyEx  until the
      function returns ERROR_NO_MORE_ITEMS. Further on,
      it's not worth to query the buffersize, if the maximum length
      is not more than 256. This eliminates the need for
      RegQueryInfoKey altogether, and it eliminates the
      possibility for race consitions.
      
      This suggestion is commited to branch
      bug-3362446 now. All test-cases pass.
      
      Agreed with this solution?
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  20. Ticket change [6a8e9f34af] (rid 128174) by nijtmans on 2012-06-19 20:25:34:

    1. assignee changed to: "nijtmans"
  21. Ticket change [8caf353e7a] (rid 127783) by apnadkarni on 2012-06-20 09:13:23:

    1. icomment:
      Seems reasonable to me. 
      
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. username: "apnadkarni"
  22. Ticket change [05fea42a02] (rid 89140) by nijtmans on 2012-06-20 14:41:36:

    1. icomment:
      The only reason I am hesitating to merge this to
      core-8-4-branch and up, is because there is no test
      case which produces the error message "unable to
      query key ...".  Maybe it was impossible from
      the start to get this error message ever: If the
      OpenKey() call succeeded alreay (so we know that
      the key exists) why would the following
      RegQueryInfoKey fail? msdn doesn't say anything
      about that, other than that RegQueryInfoKey can
      produce a system error message. But in the Tcl
      code, it seems impossible.
      
      Added test-case 6.21 now, seems that very long
      value names and values work fine.
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  23. Ticket change [5267802dbc] (rid 126311) by apnadkarni on 2012-06-21 12:07:15:

    1. icomment:
      Jan, I'm a bit confused by your last comment about not merging into core-8-4-branch and up. Does that mean you don't plan on merging into 8.6 ? Note from my original report that this problem only shows up with 8.6 since that is where the change to Unicode calls was made.
      
      /Ashok
      
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. username: "apnadkarni"
  24. Ticket change [82401511a6] (rid 117200) by nijtmans on 2012-06-21 14:04:11:

    1. icomment:
      Yes, I plan to merge this up to Tcl 8.6, but I first wanted to be sure
      that it was impossible to generate the the "unable to query key ..."
      error. That was the only possible incompatibility that I saw.
      
      All versions, from 8.4 on already use unicode API
      when running on Windows 2000+, and the original
      report mentions that the error happens in 8.5 as well.
      So it has nothing to do with the conversion to UNICODE
      (the only difference in 8.6 is that it is compiled in there,
      while in <8.6 it is runtime switchable)
      
      The main difference between 8.4 and 8.5 is that in 8.5
      the dll can be unloaded. This doesn't explain why
      the bug occurs on 8.5 and not on 8.4
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  25. Ticket change [1012de1201] (rid 94906) by nijtmans on 2012-06-21 16:52:05:

    1. closedate changed to: "2012-06-21T09:52:05"
    2. closer changed to: "nijtmans"
    3. icomment:
      Fixed now in core-8-5-branch and trunk.
      
      Not (yet) in core-8-4-branch because:
      - the original bug was not there
      - it can always be done later if desired
         (it's in the bug-3362446 branch)
      - Maybe it's better to backport
        registry-1.2.2 to 8.4 as-is.
      
      apnadkarni, Can you confirm that everything
      is OK now in 8.5 and/or trunk? Then this issue
      can be closed.
      
      
    4. login: "nijtmans"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Pending"
    8. username: "nijtmans"
  26. Ticket change [bc12cd6506] (rid 129599) by nijtmans on 2012-07-12 02:43:13:

    1. icomment:
      Little addendum: Microsoft recommends to
      keep track of the length of the buffer used in
      RegQueryValueEx in a separate value. This
      could result in undefined behavior when
      getting HKEY_PERFORMANCE_DATA.
      
      Now fixed this in core-8-5-branch and
      trunk as well.
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  27. Ticket change [ccc587148e] (rid 95764) by nijtmans on 2012-07-12 02:43:14:

    1. closedate changed to: "2012-07-11T19:43:14"
    2. closer changed to: "nijtmans"
    3. foundin changed to: "obsolete: 8.5.11"
    4. icomment:
      
      
      allow_comments - 1
      
      
      
    5. login: "nijtmans"
    6. mimetype: "text/plain"
    7. status changed to: "Closed"
    8. username: "nijtmans"