Mercurial > dnsbl
comparison 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 |
comparison
equal
deleted
inserted
replaced
243:b4bcc42c30ef | 244:ef97c7cd4a6e |
---|---|
851 } | 851 } |
852 const char *rc = env_from_default; | 852 const char *rc = env_from_default; |
853 string_map::iterator i = env_from.find(from); | 853 string_map::iterator i = env_from.find(from); |
854 if (i != env_from.end()) rc = (*i).second; // found user@domain key | 854 if (i != env_from.end()) rc = (*i).second; // found user@domain key |
855 else { | 855 else { |
856 char *x = strchr(from, '@'); | 856 const char *x = strchr(from, '@'); |
857 if (x) { | 857 if (x) { |
858 char buf[200]; | |
858 x++; | 859 x++; |
859 i = env_from.find(x); | 860 i = env_from.find(x); |
861 size_t n = x - from; // length of user name plus @ | |
860 if (i != env_from.end()) rc = (*i).second; // found domain key | 862 if (i != env_from.end()) rc = (*i).second; // found domain key |
861 else { | 863 else if (n < sizeof(buf)) { |
862 char y = *x; | 864 // we only test reasonably short user names, since we need |
863 *x = '\0'; | 865 // to copy them to a buffer to avoid a dup/free cycle on every |
864 i = env_from.find(from); | 866 // test here. |
865 *x = y; | 867 strncpy(buf, from, n); |
868 buf[n] = '\0'; | |
869 i = env_from.find(buf); | |
866 if (i != env_from.end()) rc = (*i).second; // found user@ key | 870 if (i != env_from.end()) rc = (*i).second; // found user@ key |
867 } | 871 } |
868 } | 872 } |
869 } | 873 } |
870 if ((rc == token_inherit) || (rc == token_unknown)) { | 874 if ((rc == token_inherit) || (rc == token_unknown)) { |
877 | 881 |
878 | 882 |
879 CONTEXTP CONTEXT::find_context(const char *from) { | 883 CONTEXTP CONTEXT::find_context(const char *from) { |
880 context_map::iterator i = env_from_context.find(from); | 884 context_map::iterator i = env_from_context.find(from); |
881 if (i != env_from_context.end()) return (*i).second; // found user@domain key | 885 if (i != env_from_context.end()) return (*i).second; // found user@domain key |
882 char *x = strchr(from, '@'); | 886 const char *x = strchr(from, '@'); |
883 if (x) { | 887 if (x) { |
888 char buf[200]; | |
884 x++; | 889 x++; |
885 i = env_from_context.find(x); | 890 i = env_from_context.find(x); |
891 size_t n = x - from; // length of user name plus @ | |
886 if (i != env_from_context.end()) return (*i).second; // found domain key | 892 if (i != env_from_context.end()) return (*i).second; // found domain key |
887 char y = *x; | 893 else if (n < sizeof(buf)) { |
888 *x = '\0'; | 894 // we only test reasonably short user names, since we need |
889 i = env_from_context.find(from); | 895 // to copy them to a buffer to avoid a dup/free cycle on every |
890 *x = y; | 896 // test here. |
891 if (i != env_from_context.end()) return (*i).second; // found user@ key | 897 strncpy(buf, from, n); |
898 buf[n] = '\0'; | |
899 i = env_from_context.find(buf); | |
900 if (i != env_from_context.end()) return (*i).second; // found user@ key | |
901 } | |
892 } | 902 } |
893 return this; | 903 return this; |
894 } | 904 } |
895 | 905 |
896 | 906 |