diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-06-11 15:47:44 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-06-11 15:47:44 -0700 |
commit | 3dd9240cc311f3c617d68764a6e6a1a21a77c6a6 (patch) | |
tree | ef08093422e4db1e2830542edf6f0a44e5d4726e | |
parent | 7e17343965b7275367a4f0ceb90969867f3f1410 (diff) | |
download | tcpdump-3dd9240cc311f3c617d68764a6e6a1a21a77c6a6.tar.gz |
Do case-insensitive comparisons assuming ASCII strings.
Do the case-insensitive comparisons in a locale-independent fashion that
only maps ASCII letters, in the standard English-language fashion; that
way, we don't get bitten by, for example, Turkish having separate "i
with dot" and "i without dot" letters, with lower-case "i with dot" being
mapped to upper-case "I with dot" rather than being mapped to "I".
-rw-r--r-- | INSTALL.txt | 3 | ||||
-rw-r--r-- | Makefile.in | 3 | ||||
-rw-r--r-- | ascii_strcasecmp.c (renamed from strcasecmp.c) | 66 | ||||
-rw-r--r-- | ascii_strcasecmp.h | 33 | ||||
-rw-r--r-- | config.h.in | 3 | ||||
-rwxr-xr-x | configure | 13 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | lbl/os-solaris2.h | 1 | ||||
-rw-r--r-- | lbl/os-sunos4.h | 2 | ||||
-rw-r--r-- | lbl/os-ultrix4.h | 1 | ||||
-rw-r--r-- | missing/dlnames.c | 3 | ||||
-rw-r--r-- | print-esp.c | 10 | ||||
-rw-r--r-- | tcpdump.c | 40 | ||||
-rw-r--r-- | util-print.c | 3 | ||||
-rw-r--r-- | win32/prj/WinDump.dsp | 8 | ||||
-rw-r--r-- | win32/prj/WinDump.vcproj | 44 |
16 files changed, 138 insertions, 97 deletions
diff --git a/INSTALL.txt b/INSTALL.txt index 2abadd6e..5aefc458 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -49,6 +49,8 @@ addrtoname.c - address to hostname routines addrtoname.h - address to hostname definitions ah.h - IPSEC Authentication Header definitions appletalk.h - AppleTalk definitions +ascii_strcasecmp.c - locale-independent case-independent string comparison + routines atime.awk - TCP ack awk script atm.h - ATM traffic type definitions bpf_dump.c - BPF program printing routines, in case libpcap doesn't @@ -202,7 +204,6 @@ slcompress.h - SLIP/PPP Van Jacobson compression (RFC1144) definitions smb.h - SMB/CIFS definitions smbutil.c - SMB/CIFS utility routines stime.awk - TCP send awk script -strcasecmp.c - missing routine tcp.h - TCP definitions tcpdump.1 - manual entry tcpdump.c - main program diff --git a/Makefile.in b/Makefile.in index 70f7085f..7e4f7b11 100644 --- a/Makefile.in +++ b/Makefile.in @@ -75,6 +75,7 @@ CSRC = setsignal.c tcpdump.c util.c LIBNETDISSECT_SRC=\ addrtoname.c \ af.c \ + ascii_strcasecmp.c \ checksum.c \ cpack.c \ gmpls.c \ @@ -237,6 +238,7 @@ HDR = \ af.h \ ah.h \ appletalk.h \ + ascii_strcasecmp.h \ atm.h \ chdlc.h \ cpack.h \ @@ -346,7 +348,6 @@ EXTRA_DIST = \ send-ack.awk \ smbutil.c \ stime.awk \ - strcasecmp.c \ tcpdump.1.in \ vfprintf.c \ win32/Include/w32_fzs.h \ diff --git a/strcasecmp.c b/ascii_strcasecmp.c index 7ee4e383..05e587d7 100644 --- a/strcasecmp.c +++ b/ascii_strcasecmp.c @@ -10,20 +10,19 @@ * is provided ``as is'' without express or implied warranty. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <tcpdump-stdinc.h> - -#include "interface.h" +#include "ascii_strcasecmp.h" /* - * This array is designed for mapping upper and lower case letter + * This array is designed for mapping upper and lower case letters * together for a case independent comparison. The mappings are - * based upon ascii character sequences. + * based upon ASCII character sequences; all values other than + * ASCII letters are mapped to themselves, so this is locale- + * independent and intended to be locale-independent, to avoid + * issues with, for example, "i" and "I" not being lower-case + * and upper-case versions of the same letter in Turkish, where + * there are separate "i with dot" and "i without dot" letters. */ -static const u_char charmap[] = { +static const unsigned char charmap[] = { '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', @@ -59,12 +58,12 @@ static const u_char charmap[] = { }; int -strcasecmp(s1, s2) +ascii_strcasecmp(s1, s2) const char *s1, *s2; { - register const u_char *cm = charmap, - *us1 = (u_char *)s1, - *us2 = (u_char *)s2; + register const unsigned char *cm = charmap, + *us1 = (const unsigned char *)s1, + *us2 = (const unsigned char *)s2; while (cm[*us1] == cm[*us2++]) if (*us1++ == '\0') @@ -73,16 +72,39 @@ strcasecmp(s1, s2) } int -strncasecmp(s1, s2, n) +ascii_strncasecmp(s1, s2, n) const char *s1, *s2; - register int n; + register size_t n; { - register const u_char *cm = charmap, - *us1 = (u_char *)s1, - *us2 = (u_char *)s2; + register const unsigned char *cm = charmap, + *us1 = (const unsigned char *)s1, + *us2 = (const unsigned char *)s2; - while (--n >= 0 && cm[*us1] == cm[*us2++]) - if (*us1++ == '\0') + for (;;) { + if (n == 0) { + /* + * We've run out of characters that we should + * compare, and they've all been equal; return + * 0, to indicate that the prefixes are the + * same. + */ return(0); - return(n < 0 ? 0 : cm[*us1] - cm[*--us2]); + } + if (cm[*us1] != cm[*us2++]) { + /* + * We've found a mismatch. + */ + break; + } + if (*us1++ == '\0') { + /* + * We've run out of characters *to* compare, + * and they've all been equal; return 0, to + * indicate that the strings are the same. + */ + return(0); + } + n--; + } + return(cm[*us1] - cm[*--us2]); } diff --git a/ascii_strcasecmp.h b/ascii_strcasecmp.h new file mode 100644 index 00000000..0d42c594 --- /dev/null +++ b/ascii_strcasecmp.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1988-1997 + * The Regents of the University of California. All rights reserved. + * + * Copyright (c) 1998-2012 Michael Richardson <mcr@tcpdump.org> + * The TCPDUMP project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef tcpdump_ascii_strcasecmp_h +#define tcpdump_ascii_strcasecmp_h + +#include <stddef.h> + +extern int ascii_strcasecmp(const char *, const char *); +extern int ascii_strncasecmp(const char *, const char *, size_t); + +#endif /* tcpdump_ascii_strcasecmp_h */ diff --git a/config.h.in b/config.h.in index fa38d391..ee3c1fec 100644 --- a/config.h.in +++ b/config.h.in @@ -187,9 +187,6 @@ /* Define to 1 if you have the <stdlib.h> header file. */ #undef HAVE_STDLIB_H -/* Define to 1 if you have the `strcasecmp' function. */ -#undef HAVE_STRCASECMP - /* Define to 1 if you have the `strdup' function. */ #undef HAVE_STRDUP @@ -5447,19 +5447,6 @@ esac fi -ac_fn_c_check_func "$LINENO" "strcasecmp" "ac_cv_func_strcasecmp" -if test "x$ac_cv_func_strcasecmp" = xyes; then : - $as_echo "#define HAVE_STRCASECMP 1" >>confdefs.h - -else - case " $LIBOBJS " in - *" strcasecmp.$ac_objext "* ) ;; - *) LIBOBJS="$LIBOBJS strcasecmp.$ac_objext" - ;; -esac - -fi - ac_fn_c_check_func "$LINENO" "strlcat" "ac_cv_func_strlcat" if test "x$ac_cv_func_strlcat" = xyes; then : $as_echo "#define HAVE_STRLCAT 1" >>confdefs.h diff --git a/configure.in b/configure.in index 7ee957de..0640f5a8 100644 --- a/configure.in +++ b/configure.in @@ -573,7 +573,7 @@ if test "$ac_cv_namereqd" = no; then missing_includes=yes fi -AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup strsep getopt_long) +AC_REPLACE_FUNCS(vfprintf strlcat strlcpy strdup strsep getopt_long) AC_CHECK_FUNCS(fork vfork strftime) AC_CHECK_FUNCS(setlinebuf alarm) diff --git a/lbl/os-solaris2.h b/lbl/os-solaris2.h index 9f94da97..aedba4ef 100644 --- a/lbl/os-solaris2.h +++ b/lbl/os-solaris2.h @@ -25,4 +25,3 @@ int setlinebuf(FILE *); #endif char *strerror(int); int snprintf(char *, size_t, const char *, ...); -int strcasecmp(const char *, const char *); diff --git a/lbl/os-sunos4.h b/lbl/os-sunos4.h index b7358570..0e63270b 100644 --- a/lbl/os-sunos4.h +++ b/lbl/os-sunos4.h @@ -166,12 +166,10 @@ int sscanf(char *, const char *, ...); int stat(const char *, struct stat *); int statfs(char *, struct statfs *); char *strerror(int); -int strcasecmp(const char *, const char *); #ifdef __STDC__ struct tm; #endif int strftime(char *, int, char *, struct tm *); -int strncasecmp(const char *, const char *, int); long strtol(const char *, char **, int); void sync(void); void syslog(int, const char *, ...); diff --git a/lbl/os-ultrix4.h b/lbl/os-ultrix4.h index fa1f770f..891def2b 100644 --- a/lbl/os-ultrix4.h +++ b/lbl/os-ultrix4.h @@ -34,4 +34,3 @@ int ioctl(int, int, caddr_t); int pfopen(char *, int); int setlinebuf(FILE *); int socket(int, int, int); -int strcasecmp(const char *, const char *); diff --git a/missing/dlnames.c b/missing/dlnames.c index a10cd398..c1795b3d 100644 --- a/missing/dlnames.c +++ b/missing/dlnames.c @@ -41,6 +41,7 @@ #include <string.h> #include "pcap-missing.h" +#include "ascii_strcasecmp.h" struct dlt_choice { const char *name; @@ -137,7 +138,7 @@ pcap_datalink_name_to_val(const char *name) int i; for (i = 0; dlt_choices[i].name != NULL; i++) { - if (strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1, + if (ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1, name) == 0) return (dlt_choices[i].dlt); } diff --git a/print-esp.c b/print-esp.c index 3086928e..bcd6094d 100644 --- a/print-esp.c +++ b/print-esp.c @@ -50,6 +50,8 @@ #include "interface.h" #include "extract.h" +#include "ascii_strcasecmp.h" + /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * All rights reserved. @@ -331,8 +333,8 @@ espprint_decode_authalgo(netdissect_options *ndo, } *colon = '\0'; - if(strcasecmp(colon,"sha1") == 0 || - strcasecmp(colon,"md5") == 0) { + if(ascii_strcasecmp(colon,"sha1") == 0 || + ascii_strcasecmp(colon,"md5") == 0) { sa->authlen = 12; } return 1; @@ -426,7 +428,7 @@ static void esp_print_decode_onesecret(netdissect_options *ndo, char *line, } else decode = line; - if (spikey && strcasecmp(spikey, "file") == 0) { + if (spikey && ascii_strcasecmp(spikey, "file") == 0) { /* open file and read it */ FILE *secretfile; char fileline[1024]; @@ -456,7 +458,7 @@ static void esp_print_decode_onesecret(netdissect_options *ndo, char *line, return; } - if (spikey && strcasecmp(spikey, "ikev2") == 0) { + if (spikey && ascii_strcasecmp(spikey, "ikev2") == 0) { esp_print_decode_ikeline(ndo, line, file, lineno); return; } @@ -58,7 +58,6 @@ The Regents of the University of California. All rights reserved.\n"; #ifdef WIN32 #include "w32_fzs.h" -extern int strcasecmp (const char *__s1, const char *__s2); extern int SIZE_BUF; #define off_t long #define uint UINT @@ -121,6 +120,7 @@ extern int SIZE_BUF; #include "setsignal.h" #include "gmt2local.h" #include "pcap-missing.h" +#include "ascii_strcasecmp.h" #include "print.h" @@ -996,11 +996,11 @@ main(int argc, char **argv) #ifdef HAVE_PCAP_SETDIRECTION case 'Q': - if (strcasecmp(optarg, "in") == 0) + if (ascii_strcasecmp(optarg, "in") == 0) Qflag = PCAP_D_IN; - else if (strcasecmp(optarg, "out") == 0) + else if (ascii_strcasecmp(optarg, "out") == 0) Qflag = PCAP_D_OUT; - else if (strcasecmp(optarg, "inout") == 0) + else if (ascii_strcasecmp(optarg, "inout") == 0) Qflag = PCAP_D_INOUT; else error("unknown capture direction `%s'", optarg); @@ -1033,37 +1033,37 @@ main(int argc, char **argv) break; case 'T': - if (strcasecmp(optarg, "vat") == 0) + if (ascii_strcasecmp(optarg, "vat") == 0) ndo->ndo_packettype = PT_VAT; - else if (strcasecmp(optarg, "wb") == 0) + else if (ascii_strcasecmp(optarg, "wb") == 0) ndo->ndo_packettype = PT_WB; - else if (strcasecmp(optarg, "rpc") == 0) + else if (ascii_strcasecmp(optarg, "rpc") == 0) ndo->ndo_packettype = PT_RPC; - else if (strcasecmp(optarg, "rtp") == 0) + else if (ascii_strcasecmp(optarg, "rtp") == 0) ndo->ndo_packettype = PT_RTP; - else if (strcasecmp(optarg, "rtcp") == 0) + else if (ascii_strcasecmp(optarg, "rtcp") == 0) ndo->ndo_packettype = PT_RTCP; - else if (strcasecmp(optarg, "snmp") == 0) + else if (ascii_strcasecmp(optarg, "snmp") == 0) ndo->ndo_packettype = PT_SNMP; - else if (strcasecmp(optarg, "cnfp") == 0) + else if (ascii_strcasecmp(optarg, "cnfp") == 0) ndo->ndo_packettype = PT_CNFP; - else if (strcasecmp(optarg, "tftp") == 0) + else if (ascii_strcasecmp(optarg, "tftp") == 0) ndo->ndo_packettype = PT_TFTP; - else if (strcasecmp(optarg, "aodv") == 0) + else if (ascii_strcasecmp(optarg, "aodv") == 0) ndo->ndo_packettype = PT_AODV; - else if (strcasecmp(optarg, "carp") == 0) + else if (ascii_strcasecmp(optarg, "carp") == 0) ndo->ndo_packettype = PT_CARP; - else if (strcasecmp(optarg, "radius") == 0) + else if (ascii_strcasecmp(optarg, "radius") == 0) ndo->ndo_packettype = PT_RADIUS; - else if (strcasecmp(optarg, "zmtp1") == 0) + else if (ascii_strcasecmp(optarg, "zmtp1") == 0) ndo->ndo_packettype = PT_ZMTP1; - else if (strcasecmp(optarg, "vxlan") == 0) + else if (ascii_strcasecmp(optarg, "vxlan") == 0) ndo->ndo_packettype = PT_VXLAN; - else if (strcasecmp(optarg, "pgm") == 0) + else if (ascii_strcasecmp(optarg, "pgm") == 0) ndo->ndo_packettype = PT_PGM; - else if (strcasecmp(optarg, "pgm_zmtp1") == 0) + else if (ascii_strcasecmp(optarg, "pgm_zmtp1") == 0) ndo->ndo_packettype = PT_PGM_ZMTP1; - else if (strcasecmp(optarg, "lmp") == 0) + else if (ascii_strcasecmp(optarg, "lmp") == 0) ndo->ndo_packettype = PT_LMP; else error("unknown packet type `%s'", optarg); diff --git a/util-print.c b/util-print.c index 2c3eb659..a46e12c6 100644 --- a/util-print.c +++ b/util-print.c @@ -52,6 +52,7 @@ #include <string.h> #include "interface.h" +#include "ascii_strcasecmp.h" int32_t thiszone; /* seconds offset from gmt to local time */ @@ -664,7 +665,7 @@ txtproto_print(netdissect_options *ndo, const u_char *pptr, u_int len, if (idx != 0) { /* Is this a valid request name? */ while ((cmd = *cmds++) != NULL) { - if (strcasecmp((const char *)token, cmd) == 0) { + if (ascii_strcasecmp((const char *)token, cmd) == 0) { /* Yes. */ is_reqresp = 1; break; diff --git a/win32/prj/WinDump.dsp b/win32/prj/WinDump.dsp index acafddd4..5000cb4b 100644 --- a/win32/prj/WinDump.dsp +++ b/win32/prj/WinDump.dsp @@ -93,6 +93,10 @@ SOURCE=..\..\af.c # End Source File # Begin Source File +SOURCE=..\..\ascii_strcasecmp.c +# End Source File +# Begin Source File + SOURCE=..\..\bpf_dump.c # End Source File # Begin Source File @@ -613,10 +617,6 @@ SOURCE=..\..\smbutil.c # End Source File # Begin Source File -SOURCE=..\..\strcasecmp.c -# End Source File -# Begin Source File - SOURCE=..\..\missing\strlcat.c # End Source File # Begin Source File diff --git a/win32/prj/WinDump.vcproj b/win32/prj/WinDump.vcproj index 3b998868..13f115a5 100644 --- a/win32/prj/WinDump.vcproj +++ b/win32/prj/WinDump.vcproj @@ -249,6 +249,28 @@ </FileConfiguration> </File> <File + RelativePath="..\..\ascii_strcasecmp.c" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="" + PreprocessorDefinitions="" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="" + PreprocessorDefinitions="" + /> + </FileConfiguration> + </File> + <File RelativePath="..\..\bpf_dump.c" > <FileConfiguration @@ -3113,28 +3135,6 @@ </FileConfiguration> </File> <File - RelativePath="..\..\strcasecmp.c" - > - <FileConfiguration - Name="Debug|Win32" - > - <Tool - Name="VCCLCompilerTool" - AdditionalIncludeDirectories="" - PreprocessorDefinitions="" - /> - </FileConfiguration> - <FileConfiguration - Name="Release|Win32" - > - <Tool - Name="VCCLCompilerTool" - AdditionalIncludeDirectories="" - PreprocessorDefinitions="" - /> - </FileConfiguration> - </File> - <File RelativePath="..\..\missing\strlcat.c" > <FileConfiguration |