From 6ea4cc41ef493866c4cc93c62f3a132abfcc184b Mon Sep 17 00:00:00 2001 From: Yoichi NAKAYAMA Date: Sat, 10 Mar 2012 23:15:37 +0900 Subject: [PATCH] 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) --- ChangeLog | 7 +++++++ upnp/src/api/UpnpString.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 253af6e..1929d46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -318,6 +318,13 @@ Version 1.8.0 Version 1.6.16 ******************************************************************************* +2012-03-10 Yoichi NAKAYAMA + + 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 Synchronize autoconfig.h with upnpconfig.h. diff --git a/upnp/src/api/UpnpString.c b/upnp/src/api/UpnpString.c index a5d43cb..9fe8f93 100644 --- a/upnp/src/api/UpnpString.c +++ b/upnp/src/api/UpnpString.c @@ -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;