Changeset 8762 for trunk/src


Ignore:
Timestamp:
Jun 25, 2002, 12:27:00 PM (23 years ago)
Author:
sandervl
Message:

RegQueryValueExA(/W) fix for querying the length of string key data; registry.dll returns the wrong value (too big; appears size of internal storage)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/registry.cpp

    r8693 r8762  
    1 /* $Id: registry.cpp,v 1.17 2002-06-16 08:20:16 sandervl Exp $ */
     1/* $Id: registry.cpp,v 1.18 2002-06-25 10:27:00 sandervl Exp $ */
    22
    33/*
     
    870870                               LPDWORD lpcbData)
    871871{
     872  LONG ret;
     873  DWORD dwType = 0;
     874
    872875  dprintf(("ADVAPI32:Registry key=%s", lpszValueName));
    873876
    874   return O32_RegQueryValueEx(ConvertKey(hkey),
     877  if(lpdwType == NULL) {
     878      lpdwType = &dwType;
     879  }
     880  ret = O32_RegQueryValueEx(ConvertKey(hkey),
    875881                             lpszValueName,
    876882                             lpdwReserved,
     
    878884                             lpbData,
    879885                             lpcbData);
     886
     887  if(ret == 0) {
     888      if(lpdwType)  dprintf(("key type:   %x", *lpdwType));
     889      if(lpcbData)  dprintf(("key length: %d", *lpcbData));
     890  }
     891  if(ret == 0 || ret == ERROR_MORE_DATA) {
     892      //TODO:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     893      // Probably the same bug for some other key types (binary, multi_sz, REG_EXPAND_SZ)
     894      if(*lpdwType == REG_SZ && (lpbData == NULL || ret == ERROR_MORE_DATA) && lpcbData) {
     895          dprintf(("Get the real size of the string key data"));
     896          //Get the real size of the string key data
     897          //not a nice fix; hope this is enough (there is no clear connection
     898          //between returned length and real string length (not linear for different
     899          //string sizes))
     900          *lpcbData = 4096;
     901          lpbData   = (LPBYTE)malloc(*lpcbData);
     902          if(lpcbData) {
     903              //don't overwrite return value (in case it was ERROR_MODE_DATA)
     904              O32_RegQueryValueEx(ConvertKey(hkey),
     905                                  lpszValueName,
     906                                  lpdwReserved,
     907                                  lpdwType,
     908                                  lpbData,
     909                                  lpcbData);
     910              if(lpcbData)  dprintf(("real key length: %d", *lpcbData));
     911              free(lpbData);
     912          }
     913      }
     914  }
     915  return ret;
    880916}
    881917
Note: See TracChangeset for help on using the changeset viewer.