The problem is found using Clang Address Sanitizer.
The following source code:
const int namelen = strlen(name);
for (char** p = __environ; *p; p++) {
if (!memcmp(*p, name, namelen) && (*p)[namelen] == '=') // it's a match
return *p + namelen+1; // point after =
}
may try to read beyond last string inside |__environ| variable, if the
strlen(*p) < namelen.
The solution is simple:
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 =
}
Check the length before doing memcmp().
Original issue reported on code.google.com by abys...@gmail.com on 18 Aug 2014 at 5:49
Original issue reported on code.google.com by
abys...@gmail.com
on 18 Aug 2014 at 5:49