From: Dmitry Kovalenko Date: Fri, 29 Jun 2012 06:23:14 +0000 (+0400) Subject: Added processing of null pointers in PackArguments (String argument) X-Git-Tag: accepted/tizen/mobile/20160407.001200~915^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=70302d08fcc058fd727d49a9c3742aff3e0bf32f;p=platform%2Fkernel%2Fswap-modules.git Added processing of null pointers in PackArguments (String argument) --- diff --git a/driver/events.h b/driver/events.h index 030b391..ac32279 100644 --- a/driver/events.h +++ b/driver/events.h @@ -143,32 +143,40 @@ static char *PackArguments (char *pBuffer, unsigned long nLen, const char *szFor } break; case AT_STRING: - { - const char *s = va_arg (args, const char *); - int nLengthOfString = 0, nSizeOfString; + { + const char *s = va_arg (args, const char *); + int nLengthOfString = 0, nSizeOfString; + if(!s) { + /* If string poiner is NULL then */ + s = "(null)"; + } #ifdef __KERNEL__ - if((void *)s < (void *)TASK_SIZE) { - nLengthOfString = strlen_user (s); - if(nFree < nLengthOfString) - return NULL; // no space for arg - if(strncpy_from_user(pResult, s, nLengthOfString) != (nLengthOfString-1)) - EPRINTF ("failed to copy string from user %p, bytes %d", s, nLengthOfString); + if((void *)s < (void *)TASK_SIZE) { + nLengthOfString = strlen_user (s); + if(nFree < nLengthOfString) + return NULL; // no space for arg + if(strncpy_from_user(pResult, + s, + nLengthOfString) != (nLengthOfString-1)) { + EPRINTF("failed to copy string from user %p, bytes %d", + s, nLengthOfString); } - else + } + else #endif - { - nLengthOfString = strlen (s) + 1; - if(nFree < nLengthOfString) - return NULL; // no space for arg - memcpy (pResult, s, nLengthOfString); - } - nSizeOfString = ALIGN_VALUE (nLengthOfString); - if(nFree < nSizeOfString) + { + nLengthOfString = strlen (s) + 1; + if(nFree < nLengthOfString) return NULL; // no space for arg - pResult += nSizeOfString; - nFree -= nSizeOfString; + memcpy (pResult, s, nLengthOfString); } - break; + nSizeOfString = ALIGN_VALUE (nLengthOfString); + if(nFree < nSizeOfString) + return NULL; // no space for arg + pResult += nSizeOfString; + nFree -= nSizeOfString; + } + break; case AT_ARRAY: { int nLength = va_arg (args, int);