Ignore:
Timestamp:
Oct 26, 2000, 7:21:39 PM (25 years ago)
Author:
sandervl
Message:

registry fixes (heap corruption) + VirtualAlloc change

File:
1 edited

Legend:

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

    r4510 r4534  
    1 /* $Id: registry.cpp,v 1.6 2000-10-21 14:30:47 sandervl Exp $ */
     1/* $Id: registry.cpp,v 1.7 2000-10-26 17:21:39 sandervl Exp $ */
    22
    33/*
     
    88 * Copyright 1998 Sander van Leeuwen
    99 * Copyright 1998 Patrick Haller
     10 *
     11 *
     12 * TODO: Many unicode apis are still wrong (missing unicode conversions and wrong sizes)!!!!!
    1013 *
    1114 * Project Odin Software License can be found in LICENSE.TXT
     
    439442  if(rc == ERROR_SUCCESS)
    440443  {
    441     astring = (char *)malloc(max(*arg4, *arg7));   //class & keyname
     444    astring = (char *)malloc(max(*arg4+1, *arg7+1));   //class & keyname
    442445    strcpy(astring, (char *)arg3);
    443446    AsciiToUnicode(astring, arg3);
     
    497500 *****************************************************************************/
    498501
    499 ODINFUNCTION8(LONG,RegEnumValueW,HKEY,   arg1,
    500                                  DWORD,  arg2,
    501                                  LPWSTR, arg3,
    502                                  LPDWORD,arg4,
    503                                  LPDWORD,arg5,
    504                                  LPDWORD,arg6,
    505                                  LPBYTE, arg7,
    506                                  LPDWORD,arg8)
     502ODINFUNCTION8(LONG,RegEnumValueW,HKEY,   hkey,
     503                                 DWORD,  iValue,
     504                                 LPWSTR, lpszValue,
     505                                 LPDWORD,lpcchValue,
     506                                 LPDWORD,lpdwReserved,
     507                                 LPDWORD,lpdwType,
     508                                 LPBYTE, lpbData,
     509                                 LPDWORD,lpcbData)
    507510{
    508511  char *astring;
    509   LONG  rc;
    510 
    511   rc = O32_RegEnumValue(ConvertKey(arg1),
    512                         arg2,
    513                         (char *)arg3,
    514                         arg4,
    515                         arg5,
    516                         arg6,
    517                         arg7,
    518                         arg8);
     512  LONG  rc, oldsize = 0;
     513
     514  if(lpcbData) {
     515    oldsize = *lpcbData;
     516  }
     517  rc = O32_RegEnumValue(ConvertKey(hkey),
     518                        iValue,
     519                        (char *)lpszValue,
     520                        lpcchValue,
     521                        lpdwReserved,
     522                        lpdwType,
     523                        lpbData,
     524                        lpcbData);
    519525  if(rc == ERROR_SUCCESS)
    520526  {
    521     astring = (char *)malloc(*arg4);
    522     strcpy(astring, (char *)arg3);
    523     AsciiToUnicode(astring, arg3);
     527    astring = (char *)malloc(*lpcchValue+1); //+ 0 terminator
     528    strcpy(astring, (char *)lpszValue);
     529    AsciiToUnicode(astring, lpszValue);
    524530    free(astring);
     531
     532    if(lpcbData && lpbData)
     533    {
     534        switch(*lpdwType) {
     535        case REG_SZ:
     536        case REG_EXPAND_SZ:
     537            if(oldsize < *lpcbData*sizeof(WCHAR)) {
     538                *lpcbData = *lpcbData*sizeof(WCHAR);
     539                return ERROR_MORE_DATA;
     540            }
     541            astring = (char *)malloc(*lpcbData);
     542            strcpy(astring, (char *)lpbData);
     543            lstrcpyAtoW((LPWSTR)lpbData, astring);
     544            free(astring);
     545            break;
     546        case REG_MULTI_SZ:
     547        case REG_LINK: //???
     548            dprintf(("ERROR: key data must be translated from Unicode to Ascii!!"));
     549            break;
     550        default:
     551            break;
     552        }
     553    }
     554
    525555  }
    526556  return(rc);
     
    712742 *****************************************************************************/
    713743
    714 ODINFUNCTION12(LONG,RegQueryInfoKeyW,HKEY,       arg1,
    715                                       LPWSTR,     arg2,
    716                                       LPDWORD,    arg3,
    717                                       LPDWORD,    arg4,
    718                                       LPDWORD,    arg5,
    719                                       LPDWORD,    arg6,
    720                                       LPDWORD,    arg7,
    721                                       LPDWORD,    arg8,
    722                                       LPDWORD,    arg9,
    723                                       LPDWORD,    arg10,
    724                                       LPDWORD,    arg11,
    725                                       LPFILETIME, arg12)
     744ODINFUNCTION12(LONG,RegQueryInfoKeyW,HKEY,       hkey,
     745                                     LPWSTR,     lpszClass,
     746                                     LPDWORD,    lpcchClass,
     747                                     LPDWORD,    lpdwReserved,
     748                                     LPDWORD,    lpcSubKeys,
     749                                     LPDWORD,    lpcchMaxSubKey,
     750                                     LPDWORD,    lpcchMaxClass,
     751                                     LPDWORD,    lpcValues,
     752                                     LPDWORD,    lpcchMaxValueName,
     753                                     LPDWORD,    lpcbMaxValueData,
     754                                     LPDWORD,    lpcbSecurityDescriptor,
     755                                     LPFILETIME, lpftLastWriteTime)
    726756{
    727757  char *astring;
    728758  LONG  rc;
    729759
    730   rc = O32_RegQueryInfoKey(ConvertKey(arg1),
    731                            (char *)arg2,
    732                            arg3,
    733                            arg4,
    734                            arg5,
    735                            arg6,
    736                            arg7,
    737                            arg8,
    738                            arg9,
    739                            arg10,
    740                            arg11,
    741                            arg12);
     760  rc = O32_RegQueryInfoKey(ConvertKey(hkey),
     761                           (char *)lpszClass,
     762                           lpcchClass,
     763                           lpdwReserved,
     764                           lpcSubKeys,
     765                           lpcchMaxSubKey,
     766                           lpcchMaxClass,
     767                           lpcValues,
     768                           lpcchMaxValueName,
     769                           lpcbMaxValueData,
     770                           lpcbSecurityDescriptor,
     771                           lpftLastWriteTime);
    742772  if(rc == ERROR_SUCCESS)
    743773  {
    744     if(*arg3) {
    745             astring = (char *)malloc(*arg3);
    746         strcpy(astring, (char *)arg2);
    747             AsciiToUnicode(astring, arg2);
     774    if(*lpcchClass) {
     775            astring = (char *)malloc(*lpcchClass+1); //returned length does NOT include 0 terminator
     776            strcpy(astring, (char *)lpszClass);
     777            AsciiToUnicode(astring, lpszClass);
    748778            free(astring);
    749779    }
    750     else    *arg2 = 0;
     780    else    *lpszClass = 0;
    751781  }
     782  //TODO: lpcbMaxValueData could be wrong for string key values!!! (as it's in bytes)
    752783  return(rc);
    753784}
     
    808839  {
    809840    if(pcbValue) {
    810             astring2 = (char *)malloc(*pcbValue);
     841            astring2 = (char *)malloc(*pcbValue);   //includes 0 terminator
    811842            strcpy(astring2, (char *)lpszValue);
    812843            AsciiToUnicode(astring2, lpszValue);
Note: See TracChangeset for help on using the changeset viewer.