[pywin32-checkins] pywin32/win32/src PySECURITY_DESCRIPTOR.cpp, 1.16, 1.17
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2006-12-04 03:51:54
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29412/win32/src Modified Files: PySECURITY_DESCRIPTOR.cpp Log Message: Add allocation error checking in _MakeAbsoluteSD, remove a couple of extraneous InitializeSecurityDescriptor calls Index: PySECURITY_DESCRIPTOR.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PySECURITY_DESCRIPTOR.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** PySECURITY_DESCRIPTOR.cpp 28 Jan 2005 08:50:20 -0000 1.16 --- PySECURITY_DESCRIPTOR.cpp 4 Dec 2006 03:51:52 -0000 1.17 *************** *** 187,195 **** DWORD ownersize = 0; DWORD groupsize = 0; psd_absolute = malloc(sdsize); ZeroMemory(psd_absolute,sdsize); - ::InitializeSecurityDescriptor(psd_absolute,SECURITY_DESCRIPTOR_REVISION); - BOOL resize = FALSE; if(MakeAbsoluteSD(psd_relative, psd_absolute, &sdsize, --- 187,198 ---- DWORD ownersize = 0; DWORD groupsize = 0; + BOOL resize = FALSE; psd_absolute = malloc(sdsize); + if (psd_absolute==NULL){ + PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", sdsize); + goto error_exit; + } ZeroMemory(psd_absolute,sdsize); if(MakeAbsoluteSD(psd_relative, psd_absolute, &sdsize, *************** *** 203,237 **** free (psd_absolute); psd_absolute = malloc(sdsize); ! ::InitializeSecurityDescriptor(psd_absolute,SECURITY_DESCRIPTOR_REVISION); } if (daclsize > 0){ resize = TRUE; pdacl = (ACL *)malloc(daclsize); } if (saclsize > 0){ resize = TRUE; psacl = (ACL *)malloc(saclsize); } if (ownersize > 0){ resize = TRUE; powner = (SID *)malloc(ownersize); } if (groupsize > 0){ resize = TRUE; pgroup = (SID *)malloc(groupsize); } ! if (!resize){ ! FreeAbsoluteSD(psd_absolute); ! PyWin_SetAPIError("MakeAbsoluteSD"); ! return FALSE; ! } ! if(MakeAbsoluteSD(psd_relative, psd_absolute, &sdsize, ! pdacl, &daclsize, psacl, &saclsize, ! powner, &ownersize, pgroup, &groupsize)){ *ppsd_absolute = psd_absolute; return TRUE; } - FreeAbsoluteSD(psd_absolute); PyWin_SetAPIError("MakeAbsoluteSD"); return FALSE; } --- 206,268 ---- free (psd_absolute); psd_absolute = malloc(sdsize); ! if (psd_absolute==NULL){ ! PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", sdsize); ! goto error_exit; ! } ! ZeroMemory(psd_absolute,sdsize); } if (daclsize > 0){ resize = TRUE; pdacl = (ACL *)malloc(daclsize); + if (pdacl==NULL){ + PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", daclsize); + goto error_exit; + } } if (saclsize > 0){ resize = TRUE; psacl = (ACL *)malloc(saclsize); + if (psacl==NULL){ + PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", saclsize); + goto error_exit; + } } if (ownersize > 0){ resize = TRUE; powner = (SID *)malloc(ownersize); + if (powner==NULL){ + PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", ownersize); + goto error_exit; + } } if (groupsize > 0){ resize = TRUE; pgroup = (SID *)malloc(groupsize); + if (pgroup==NULL){ + PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", groupsize); + goto error_exit; + } } ! if (resize && MakeAbsoluteSD(psd_relative, psd_absolute, &sdsize, ! pdacl, &daclsize, psacl, &saclsize, ! powner, &ownersize, pgroup, &groupsize)){ *ppsd_absolute = psd_absolute; return TRUE; } PyWin_SetAPIError("MakeAbsoluteSD"); + + error_exit: + *ppsd_absolute=NULL; + // *Don't* use FreeAbsoluteSD aince function may exit without the sd having been constructed yet + if (psd_absolute!=NULL) + free(psd_absolute); + if (pdacl!=NULL) + free(pdacl); + if (psacl!=NULL) + free(psacl); + if (powner!=NULL) + free(powner); + if (pgroup!=NULL) + free(pgroup); return FALSE; } |