Handle allocation error in strndup to avoid access violation.

Return NULL before calling strncpy.
Platforms with HAVE_STRNDUP are not affected.
(cherry picked from commit 194397b6d62b0a9910075ec07ecb77df6929abc8)
This commit is contained in:
Yoichi NAKAYAMA 2012-03-10 23:15:37 +09:00 committed by Marcelo Roberto Jimenez
parent 2b3f5bbcee
commit 6ea4cc41ef
2 changed files with 9 additions and 0 deletions

View File

@ -318,6 +318,13 @@ Version 1.8.0
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>
Synchronize autoconfig.h with upnpconfig.h.

View File

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