issue-644: fix possible out-of-bounds access in GetenvBeforeMain

As suggested by user Ivan L.
This commit is contained in:
Aliaksey Kandratsenka 2014-08-19 08:14:08 -07:00
parent f1ae3c446f
commit 3c326d9f20
1 changed files with 3 additions and 0 deletions

View File

@ -124,6 +124,9 @@ const char* GetenvBeforeMain(const char* name) {
if (__environ) { // can exist but be NULL, if statically linked
const int namelen = strlen(name);
for (char** p = __environ; *p; p++) {
if (strlen(*p) < namelen) {
continue;
}
if (!memcmp(*p, name, namelen) && (*p)[namelen] == '=') // it's a match
return *p + namelen+1; // point after =
}