Mercurial > dnsbl
diff src/context.cpp @ 244:ef97c7cd4a6e stable-6-0-27
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 15 Aug 2011 21:08:11 -0700 |
parents | 5c3e9bf45bb5 |
children | 15bf4f68a0b2 |
line wrap: on
line diff
--- a/src/context.cpp Fri Nov 19 13:04:47 2010 -0800 +++ b/src/context.cpp Mon Aug 15 21:08:11 2011 -0700 @@ -853,16 +853,20 @@ string_map::iterator i = env_from.find(from); if (i != env_from.end()) rc = (*i).second; // found user@domain key else { - char *x = strchr(from, '@'); + const char *x = strchr(from, '@'); if (x) { + char buf[200]; x++; i = env_from.find(x); + size_t n = x - from; // length of user name plus @ if (i != env_from.end()) rc = (*i).second; // found domain key - else { - char y = *x; - *x = '\0'; - i = env_from.find(from); - *x = y; + else if (n < sizeof(buf)) { + // we only test reasonably short user names, since we need + // to copy them to a buffer to avoid a dup/free cycle on every + // test here. + strncpy(buf, from, n); + buf[n] = '\0'; + i = env_from.find(buf); if (i != env_from.end()) rc = (*i).second; // found user@ key } } @@ -879,17 +883,23 @@ CONTEXTP CONTEXT::find_context(const char *from) { context_map::iterator i = env_from_context.find(from); if (i != env_from_context.end()) return (*i).second; // found user@domain key - char *x = strchr(from, '@'); + const char *x = strchr(from, '@'); if (x) { + char buf[200]; x++; i = env_from_context.find(x); + size_t n = x - from; // length of user name plus @ if (i != env_from_context.end()) return (*i).second; // found domain key - char y = *x; - *x = '\0'; - i = env_from_context.find(from); - *x = y; + else if (n < sizeof(buf)) { + // we only test reasonably short user names, since we need + // to copy them to a buffer to avoid a dup/free cycle on every + // test here. + strncpy(buf, from, n); + buf[n] = '\0'; + i = env_from_context.find(buf); if (i != env_from_context.end()) return (*i).second; // found user@ key } + } return this; }