Various bug fixes:

* Allow the / char in the char_check routine
* Added debug for field checking
* Fixed handling of the 0xaabbccdd form
* Always set buffer 1 if it is available - previously dotted quad
  did not set this buffer.
* Fixed segv if no dots found
This commit is contained in:
blymn 2001-02-13 01:00:11 +00:00
parent c52d4f59e8
commit 95df9c4076

View File

@ -1,4 +1,4 @@
/* $NetBSD: type_ipv4.c,v 1.4 2001/02/10 14:57:53 blymn Exp $ */ /* $NetBSD: type_ipv4.c,v 1.5 2001/02/13 01:00:11 blymn Exp $ */
/*- /*-
* Copyright (c) 1998-1999 Brett Lymn * Copyright (c) 1998-1999 Brett Lymn
@ -69,6 +69,9 @@ ipv4_check_field(FIELD *field, char *args)
if (asprintf(&keeper, "%s", args) < 0) if (asprintf(&keeper, "%s", args) < 0)
return FALSE; return FALSE;
#ifdef DEBUG
fprintf(dbg, "ipv4_check_field: enter with args of %s\n", keeper);
#endif
style = FORMI_DOTTED_QUAD; style = FORMI_DOTTED_QUAD;
buf = keeper; buf = keeper;
@ -94,7 +97,7 @@ ipv4_check_field(FIELD *field, char *args)
case FORMI_DOTTED_QUAD: case FORMI_DOTTED_QUAD:
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
p = strsep(&buf, "."); p = strsep(&buf, ".");
if (*p == '\0') if ((p == NULL) || (*p == '\0'))
goto FAIL; goto FAIL;
vals[i] = atoi(p); vals[i] = atoi(p);
if (vals[i] > 255) if (vals[i] > 255)
@ -107,20 +110,16 @@ ipv4_check_field(FIELD *field, char *args)
hex_val = strtoul(buf, NULL, 16); hex_val = strtoul(buf, NULL, 16);
if ((hex_val == ULONG_MAX) && (errno == ERANGE)) if ((hex_val == ULONG_MAX) && (errno == ERANGE))
goto FAIL; goto FAIL;
working = hex_val; working = hex_val;
for (i = 3; i < 0; i--) { for (i = 3; i >= 0; i--) {
vals[i] = (unsigned int)(working & 0xff); vals[i] = (unsigned int)(working & 0xffUL);
working = working >> 8; working = working >> 8;
} }
break; break;
} }
/* check for null buffer pointer, indicates trailing garbage */
if (buf != NULL)
goto FAIL;
free(keeper); free(keeper);
buf1 = NULL; buf1 = NULL;
@ -130,6 +129,9 @@ ipv4_check_field(FIELD *field, char *args)
if (asprintf(&buf, "%d.%d.%d.%d", vals[0], vals[1], vals[2], if (asprintf(&buf, "%d.%d.%d.%d", vals[0], vals[1], vals[2],
vals[3]) < 0) vals[3]) < 0)
return FALSE; return FALSE;
if (asprintf(&buf1, "%d.%d.%d.%d", vals[0], vals[1],
vals[2], vals[3]) < 0)
return FALSE;
break; break;
case FORMI_CLASSLESS: case FORMI_CLASSLESS:
@ -157,12 +159,15 @@ ipv4_check_field(FIELD *field, char *args)
* Set the field buffer 1 to the dotted quad format regardless * Set the field buffer 1 to the dotted quad format regardless
* of the input format, only if buffer 1 exists. * of the input format, only if buffer 1 exists.
*/ */
if ((field->nbuf > 1) && (buf1 != NULL)) if (field->nbuf > 1)
set_field_buffer(field, 1, buf1); set_field_buffer(field, 1, buf1);
#ifdef DEBUG
fprintf(dbg, "ipv4_check_field: buf0 set to %s\n", buf);
fprintf(dbg, "ipv4_check_field: buf1 set to %s\n", buf1);
#endif
free(buf); free(buf);
if (buf1 != NULL) free(buf1);
free(buf1);
return TRUE; return TRUE;
@ -179,8 +184,8 @@ ipv4_check_field(FIELD *field, char *args)
static int static int
ipv4_check_char(/* ARGSUSED1 */ int c, char *args) ipv4_check_char(/* ARGSUSED1 */ int c, char *args)
{ {
return (isxdigit(c) || (c == '.') || (tolower(c) == 'x')) return (isxdigit(c) || (c == '.') || (tolower(c) == 'x') ||
? TRUE : FALSE; (c == '/'))? TRUE : FALSE;
} }
static FIELDTYPE builtin_ipv4 = { static FIELDTYPE builtin_ipv4 = {