Handle allocation error in strndup to avoid access violation.

Return NULL before calling strncpy.
Platforms with HAVE_STRNDUP are not affected.
This commit is contained in:
Yoichi NAKAYAMA 2012-03-10 23:15:37 +09:00
parent b78eaf4e43
commit 194397b6d6
2 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,13 @@
Version 1.6.16 Version 1.6.16
******************************************************************************* *******************************************************************************
2012-03-10 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
Handle allocation error in strndup to avoid access violation.
Return NULL before calling strncpy.
Platforms with HAVE_STRNDUP are not affected.
2012-03-10 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com> 2012-03-10 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
Synchronize autoconfig.h with upnpconfig.h. Synchronize autoconfig.h with upnpconfig.h.

View File

@ -50,6 +50,8 @@
{ {
size_t strsize = strnlen(__string, __n); size_t strsize = strnlen(__string, __n);
char *newstr = (char *)malloc(strsize + 1); char *newstr = (char *)malloc(strsize + 1);
if (newstr == NULL)
return NULL;
strncpy(newstr, __string, strsize); strncpy(newstr, __string, strsize);
newstr[strsize] = 0; newstr[strsize] = 0;