Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 8b2d76a55320b1a6ae47987fb6e7b7c2583ca85d
Ticket: 3362446fffffffffffffffffffffffffffffffff
registry keys command fails with 8.5/8.6
User & Date: apnadkarni on 2011-07-11 14:07:44
Changes

  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"