summaryrefslogtreecommitdiff
path: root/etherent.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-08-31 17:54:51 -0700
committerGuy Harris <guy@alum.mit.edu>2019-08-31 17:54:51 -0700
commit5a418352f3a1ca4f049396d7892d6e74f4011197 (patch)
tree4e2cfcbd3b442002b2d5d7b4524191d977856ebd /etherent.c
parent5807299ed17700b838b99c93e644346c5e055914 (diff)
downloadlibpcap-5a418352f3a1ca4f049396d7892d6e74f4011197.tar.gz
Don't use ctype.h macros.
Some of them are locale-dependent, and all of them run the risk of failing if you hand them a char with the 8th bit set. Define our own locale-independent macros that can be handed any integral value. Don't include <ctype.h>. This should address the issue in GitHub pull request #839, and should also catch any (highly unlikely) cases in which something other than Boring Old Space And Tab and, sometimes, CR and LF are treated as white space. (No, we don't want FF or VT treated as white space.)
Diffstat (limited to 'etherent.c')
-rw-r--r--etherent.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/etherent.c b/etherent.c
index 5f499613..e883a9c7 100644
--- a/etherent.c
+++ b/etherent.c
@@ -25,7 +25,6 @@
#include <pcap-types.h>
-#include <ctype.h>
#include <memory.h>
#include <stdio.h>
#include <string.h>
@@ -45,14 +44,18 @@ static inline int skip_line(FILE *);
static inline u_char
xdtoi(u_char c)
{
- if (isdigit(c))
+ if (c >= '0' && c < '9')
return (u_char)(c - '0');
- else if (islower(c))
+ else if (c >= 'a' && c <= 'f')
return (u_char)(c - 'a' + 10);
else
return (u_char)(c - 'A' + 10);
}
+/*
+ * Skip linear white space (space and tab) and any CRs before LF.
+ * Stop when we hit a non-white-space character or an end-of-line LF.
+ */
static inline int
skip_space(FILE *f)
{
@@ -60,7 +63,7 @@ skip_space(FILE *f)
do {
c = getc(f);
- } while (isspace(c) && c != '\n');
+ } while (PCAP_ISLWSP(c) || c == '\r');
return c;
}
@@ -97,7 +100,7 @@ pcap_next_etherent(FILE *fp)
/* If this is a comment, or first thing on line
cannot be Ethernet address, skip the line. */
- if (!isxdigit(c)) {
+ if (!PCAP_ISXDIGIT(c)) {
c = skip_line(fp);
if (c == EOF)
return (NULL);
@@ -110,7 +113,7 @@ pcap_next_etherent(FILE *fp)
c = getc(fp);
if (c == EOF)
return (NULL);
- if (isxdigit(c)) {
+ if (PCAP_ISXDIGIT(c)) {
d <<= 4;
d |= xdtoi((u_char)c);
c = getc(fp);
@@ -126,7 +129,7 @@ pcap_next_etherent(FILE *fp)
}
/* Must be whitespace */
- if (!isspace(c)) {
+ if (!PCAP_ISSPACE(c)) {
c = skip_line(fp);
if (c == EOF)
return (NULL);
@@ -156,7 +159,7 @@ pcap_next_etherent(FILE *fp)
c = getc(fp);
if (c == EOF)
return (NULL);
- } while (!isspace(c) && --namesize != 0);
+ } while (!PCAP_ISSPACE(c) && --namesize != 0);
*bp = '\0';
/* Eat trailing junk */