diff options
author | Guy Harris <guy@alum.mit.edu> | 2007-11-27 18:52:51 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2007-11-27 18:52:51 +0000 |
commit | 9c89cdaaa3eccfe74d4e17705f38508c640b5047 (patch) | |
tree | 593646c7e1eb44302243659672c5fc691f0d4272 /epan/dissectors/packet-diameter.c | |
parent | a189f34b84345d6851a489c484c01c1bf21f56d1 (diff) | |
download | wireshark-9c89cdaaa3eccfe74d4e17705f38508c640b5047.tar.gz wireshark-9c89cdaaa3eccfe74d4e17705f38508c640b5047.tar.bz2 wireshark-9c89cdaaa3eccfe74d4e17705f38508c640b5047.zip |
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
Diffstat (limited to 'epan/dissectors/packet-diameter.c')
-rw-r--r-- | epan/dissectors/packet-diameter.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/epan/dissectors/packet-diameter.c b/epan/dissectors/packet-diameter.c index 129c887327..d235b9d99d 100644 --- a/epan/dissectors/packet-diameter.c +++ b/epan/dissectors/packet-diameter.c @@ -955,18 +955,43 @@ static const avp_type_t basic_types[] = { +/* + * This is like g_str_hash() (as of GLib 2.4.8), but it maps all + * upper-case ASCII characters to their ASCII lower-case equivalents. + * We can't use g_strdown(), as that doesn't do an ASCII mapping; + * in Turkish locales, for example, there are two lower-case "i"s + * and two upper-case "I"s, with and without dots - the ones with + * dots map between each other, as do the ones without dots, so "I" + * doesn't map to "i". + */ static guint strcase_hash(gconstpointer key) { - char* k = ep_strdup(key); - g_strdown(k); - return g_str_hash(k); + const char *p = key; + guint h = *p; + char c; + + if (h) { + if (h >= 'A' && h <= 'Z') + h = h - 'A' + 'a'; + for (p += 1; *p != '\0'; p++) { + c = *p; + if (c >= 'A' && c <= 'Z') + c = c - 'A' + 'a'; + h = (h << 5) - h + c; + } + } + + return h; } +/* + * Again, use g_ascii_strcasecmp(), not strcasecmp(), so that only ASCII + * letters are mapped, and they're mapped to the lower-case ASCII + * equivalents. + */ static gboolean strcase_equal(gconstpointer ka, gconstpointer kb) { - char* a = ep_strdup(ka); - char* b = ep_strdup(kb); - g_strdown(a); - g_strdown(b); - return g_str_equal(a,b); + const char* a = ka; + const char* b = kb; + return g_ascii_strcasecmp(a,b) == 0; } extern int dictionary_load(void); |