2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-04 16:45:24 +00:00

Replace usage of strsep with POSIX strtok_r()

This commit is contained in:
Ondřej Surý
2018-03-21 21:08:29 +00:00
parent b9552250cb
commit 921d05ddcf
17 changed files with 109 additions and 330 deletions

View File

@@ -943,18 +943,6 @@ cleanup:
return (result); return (result);
} }
static char *
next_token(char **stringp, const char *delim) {
char *res;
do {
res = strsep(stringp, delim);
if (res == NULL)
break;
} while (*res == '\0');
return (res);
}
static isc_result_t static isc_result_t
parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max, parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
const char *desc) { const char *desc) {
@@ -974,23 +962,21 @@ parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
static void static void
plus_option(char *option) { plus_option(char *option) {
isc_result_t result; isc_result_t result;
char option_store[256]; char *cmd, *value, *last;
char *cmd, *value, *ptr;
isc_boolean_t state = ISC_TRUE; isc_boolean_t state = ISC_TRUE;
strlcpy(option_store, option, sizeof(option_store)); cmd = strtok_r(option, "=", &last);
ptr = option_store;
cmd = next_token(&ptr,"=");
if (cmd == NULL) { if (cmd == NULL) {
printf(";; Invalid option %s\n", option_store); printf(";; Invalid option %s\n", option);
return; return;
} }
value = ptr;
if (strncasecmp(cmd, "no", 2)==0) { if (strncasecmp(cmd, "no", 2)==0) {
cmd += 2; cmd += 2;
state = ISC_FALSE; state = ISC_FALSE;
} }
value = strtok_r(NULL, "\0", &last);
#define FULLCHECK(A) \ #define FULLCHECK(A) \
do { \ do { \
size_t _l = strlen(cmd); \ size_t _l = strlen(cmd); \

View File

@@ -729,28 +729,25 @@ printgreeting(int argc, char **argv, dig_lookup_t *lookup) {
*/ */
static void static void
plus_option(const char *option, isc_boolean_t is_batchfile, plus_option(char *option, isc_boolean_t is_batchfile,
dig_lookup_t *lookup) dig_lookup_t *lookup)
{ {
isc_result_t result; isc_result_t result;
char option_store[256]; char *cmd, *value, *last, *code;
char *cmd, *value, *ptr, *code;
isc_uint32_t num; isc_uint32_t num;
isc_boolean_t state = ISC_TRUE; isc_boolean_t state = ISC_TRUE;
size_t n; size_t n;
strlcpy(option_store, option, sizeof(option_store)); if ((cmd = strtok_r(option, "=", &last)) == NULL) {
ptr = option_store; printf(";; Invalid option %s\n", option);
cmd = next_token(&ptr, "=");
if (cmd == NULL) {
printf(";; Invalid option %s\n", option_store);
return; return;
} }
value = ptr;
if (strncasecmp(cmd, "no", 2)==0) { if (strncasecmp(cmd, "no", 2)==0) {
cmd += 2; cmd += 2;
state = ISC_FALSE; state = ISC_FALSE;
} }
/* parse the rest of the string */
value = strtok_r(NULL, "", &last);
#define FULLCHECK(A) \ #define FULLCHECK(A) \
do { \ do { \
@@ -1006,8 +1003,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
"specified"); "specified");
goto exit_or_usage; goto exit_or_usage;
} }
code = next_token(&value, ":"); char *extra;
save_opt(lookup, code, value); code = strtok_r(value, ":", &last);
extra = strtok_r(NULL, "\0", &last);
save_opt(lookup, code, extra);
break; break;
default: default:
goto invalid_option; goto invalid_option;
@@ -1524,7 +1523,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
isc_boolean_t config_only, int argc, char **argv, isc_boolean_t config_only, int argc, char **argv,
isc_boolean_t *firstarg) isc_boolean_t *firstarg)
{ {
char opt, *value, *ptr, *ptr2, *ptr3; char opt, *value, *ptr, *ptr2, *ptr3, *last;
isc_result_t result; isc_result_t result;
isc_boolean_t value_from_next; isc_boolean_t value_from_next;
isc_textregion_t tr; isc_textregion_t tr;
@@ -1738,15 +1737,13 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
value); value);
return (value_from_next); return (value_from_next);
case 'y': case 'y':
ptr = next_token(&value, ":"); /* hmac type or name */ if ((ptr = strtok_r(value, ":", &last)) == NULL) {
if (ptr == NULL) {
usage(); usage();
} }
ptr2 = next_token(&value, ":"); /* name or secret */ if ((ptr2 = strtok_r(NULL, ":", &last)) == NULL) { /* name or secret */
if (ptr2 == NULL)
usage(); usage();
ptr3 = next_token(&value, ":"); /* secret or NULL */ }
if (ptr3 != NULL) { if ((ptr3 = strtok_r(NULL, ":", &last)) != NULL) { /* secret or NULL */
parse_hmac(ptr); parse_hmac(ptr);
ptr = ptr2; ptr = ptr2;
ptr2 = ptr3; ptr2 = ptr3;
@@ -1758,6 +1755,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
#endif #endif
digestbits = 0; digestbits = 0;
} }
/* XXXONDREJ: FIXME */
strlcpy(keynametext, ptr, sizeof(keynametext)); strlcpy(keynametext, ptr, sizeof(keynametext));
strlcpy(keysecret, ptr2, sizeof(keysecret)); strlcpy(keysecret, ptr2, sizeof(keysecret));
return (value_from_next); return (value_from_next);
@@ -1859,10 +1857,9 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
char **rv; char **rv;
#ifndef NOPOSIX #ifndef NOPOSIX
char *homedir; char *homedir;
char rcfile[256]; char rcfile[PATH_MAX];
#endif #endif
char *input; char *last;
int i;
isc_boolean_t need_clone = ISC_TRUE; isc_boolean_t need_clone = ISC_TRUE;
/* /*
@@ -1892,32 +1889,23 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
homedir = getenv("HOME"); homedir = getenv("HOME");
if (homedir != NULL) { if (homedir != NULL) {
unsigned int n; unsigned int n;
n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc", n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc", homedir);
homedir); if (n < sizeof(rcfile)) {
if (n < sizeof(rcfile))
batchfp = fopen(rcfile, "r"); batchfp = fopen(rcfile, "r");
}
} }
if (batchfp != NULL) { if (batchfp != NULL) {
while (fgets(batchline, sizeof(batchline), while (fgets(batchline, sizeof(batchline), batchfp) != 0) {
batchfp) != 0) {
debug("config line %s", batchline); debug("config line %s", batchline);
bargc = 1; for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
input = batchline; bargc < 62 && bargv[bargc];
bargv[bargc] = next_token(&input, " \t\r\n"); bargv[++bargc] = strtok_r(NULL, " \t\r\n", &last))
while ((bargc < 62) && (bargv[bargc] != NULL)) { {
bargc++; debug(".digrc argv %d: %s", bargc, bargv[bargc]);
bargv[bargc] =
next_token(&input, " \t\r\n");
} }
bargv[0] = argv[0]; bargv[0] = argv[0];
argv0 = argv[0]; argv0 = argv[0];
parse_args(ISC_TRUE, ISC_TRUE, bargc, (char **)bargv);
for(i = 0; i < bargc; i++)
debug(".digrc argv %d: %s",
i, bargv[i]);
parse_args(ISC_TRUE, ISC_TRUE, bargc,
(char **)bargv);
} }
fclose(batchfp); fclose(batchfp);
} }
@@ -1928,8 +1916,9 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
/* Processing '-f batchfile'. */ /* Processing '-f batchfile'. */
lookup = clone_lookup(default_lookup, ISC_TRUE); lookup = clone_lookup(default_lookup, ISC_TRUE);
need_clone = ISC_FALSE; need_clone = ISC_FALSE;
} else } else {
lookup = default_lookup; lookup = default_lookup;
}
rc = argc; rc = argc;
rv = argv; rv = argv;
@@ -2101,18 +2090,15 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
if (batchline[0] == '\r' || batchline[0] == '\n' if (batchline[0] == '\r' || batchline[0] == '\n'
|| batchline[0] == '#' || batchline[0] == ';') || batchline[0] == '#' || batchline[0] == ';')
goto next_line; goto next_line;
input = batchline; for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
bargv[bargc] = next_token(&input, " \t\r\n"); (bargc < 14) && bargv[bargc];
while ((bargc < 14) && (bargv[bargc] != NULL)) { bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last)) {
bargc++; debug("batch argv %d: %s", bargc, bargv[bargc]);
bargv[bargc] = next_token(&input, " \t\r\n");
} }
bargv[0] = argv[0]; bargv[0] = argv[0];
argv0 = argv[0]; argv0 = argv[0];
for(i = 0; i < bargc; i++)
debug("batch argv %d: %s", i, bargv[i]);
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv); parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
return; return;
} }
@@ -2151,8 +2137,6 @@ query_finished(void) {
char batchline[MXNAME]; char batchline[MXNAME];
int bargc; int bargc;
char *bargv[16]; char *bargv[16];
char *input;
int i;
if (batchname == NULL) { if (batchname == NULL) {
isc_app_shutdown(); isc_app_shutdown();
@@ -2169,19 +2153,17 @@ query_finished(void) {
} }
if (fgets(batchline, sizeof(batchline), batchfp) != 0) { if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
char *last;
debug("batch line %s", batchline); debug("batch line %s", batchline);
bargc = 1; for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
input = batchline; bargc < 14 && bargv[bargc];
bargv[bargc] = next_token(&input, " \t\r\n"); bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last))
while ((bargc < 14) && (bargv[bargc] != NULL)) { {
bargc++; debug("batch argv %d: %s", bargc, bargv[bargc]);
bargv[bargc] = next_token(&input, " \t\r\n");
} }
bargv[0] = argv0; bargv[0] = argv0;
for(i = 0; i < bargc; i++)
debug("batch argv %d: %s", i, bargv[i]);
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv); parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
start_lookup(); start_lookup();
} else { } else {

View File

@@ -242,18 +242,6 @@ check_next_lookup(dig_lookup_t *lookup);
static isc_boolean_t static isc_boolean_t
next_origin(dig_lookup_t *oldlookup); next_origin(dig_lookup_t *oldlookup);
char *
next_token(char **stringp, const char *delim) {
char *res;
do {
res = strsep(stringp, delim);
if (res == NULL)
break;
} while (*res == '\0');
return (res);
}
static int static int
count_dots(char *string) { count_dots(char *string) {
char *s; char *s;

View File

@@ -369,9 +369,6 @@ destroy_libs(void);
void void
set_search_domain(char *domain); set_search_domain(char *domain);
char *
next_token(char **stringp, const char *delim);
/* /*
* Routines to be defined in dig.c, host.c, and nslookup.c. and * Routines to be defined in dig.c, host.c, and nslookup.c. and
* then assigned to the appropriate function pointer * then assigned to the appropriate function pointer

View File

@@ -813,12 +813,12 @@ addlookup(char *opt) {
static void static void
do_next_command(char *input) { do_next_command(char *input) {
char *ptr, *arg; char *ptr, *arg, *last;
ptr = next_token(&input, " \t\r\n"); if ((ptr = strtok_r(input, " \t\r\n", &last)) == NULL) {
if (ptr == NULL)
return; return;
arg = next_token(&input, " \t\r\n"); }
arg = strtok_r(NULL, " \t\r\n", &last);
if ((strcasecmp(ptr, "set") == 0) && if ((strcasecmp(ptr, "set") == 0) &&
(arg != NULL)) (arg != NULL))
setoption(arg); setoption(arg);

View File

@@ -1003,36 +1003,24 @@ named_os_gethostname(char *buf, size_t len) {
return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE); return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE);
} }
static char *
next_token(char **stringp, const char *delim) {
char *res;
do {
res = strsep(stringp, delim);
if (res == NULL)
break;
} while (*res == '\0');
return (res);
}
void void
named_os_shutdownmsg(char *command, isc_buffer_t *text) { named_os_shutdownmsg(char *command, isc_buffer_t *text) {
char *input, *ptr; char *last, *ptr;
pid_t pid; pid_t pid;
input = command;
/* Skip the command name. */ /* Skip the command name. */
ptr = next_token(&input, " \t"); if ((ptr = strtok_r(command, " \t", &last)) == NULL) {
if (ptr == NULL)
return; return;
}
ptr = next_token(&input, " \t"); if ((ptr = strtok_r(NULL, " \t", &last)) == NULL) {
if (ptr == NULL)
return; return;
}
if (strcmp(ptr, "-p") != 0) if (strcmp(ptr, "-p") != 0) {
return; return;
}
#ifdef HAVE_LINUXTHREADS #ifdef HAVE_LINUXTHREADS
pid = mainpid; pid = mainpid;

View File

@@ -795,18 +795,6 @@ help(void) {
stdout); stdout);
} }
static char *
next_token(char **stringp, const char *delim) {
char *res;
do {
res = strsep(stringp, delim);
if (res == NULL)
break;
} while (*res == '\0');
return (res);
}
ISC_PLATFORM_NORETURN_PRE static void ISC_PLATFORM_NORETURN_PRE static void
fatal(const char *format, ...) fatal(const char *format, ...)
ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST; ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
@@ -1037,24 +1025,21 @@ static void
plus_option(char *option, struct query *query, isc_boolean_t global) plus_option(char *option, struct query *query, isc_boolean_t global)
{ {
isc_result_t result; isc_result_t result;
char option_store[256]; char *cmd, *value, *last, *code;
char *cmd, *value, *ptr, *code;
isc_uint32_t num; isc_uint32_t num;
isc_boolean_t state = ISC_TRUE; isc_boolean_t state = ISC_TRUE;
size_t n; size_t n;
strlcpy(option_store, option, sizeof(option_store)); if ((cmd = strtok_r(option, "=", &last)) == NULL) {
ptr = option_store; printf(";; Invalid option %s\n", option);
cmd = next_token(&ptr, "=");
if (cmd == NULL) {
printf(";; Invalid option %s\n", option_store);
return; return;
} }
value = ptr;
if (strncasecmp(cmd, "no", 2) == 0) { if (strncasecmp(cmd, "no", 2) == 0) {
cmd += 2; cmd += 2;
state = ISC_FALSE; state = ISC_FALSE;
} }
/* parse the rest of the string */
value = strtok_r(NULL, "", &last);
#define FULLCHECK(A) \ #define FULLCHECK(A) \
do { \ do { \
@@ -1279,7 +1264,7 @@ plus_option(char *option, struct query *query, isc_boolean_t global)
fatal("ednsopt no " fatal("ednsopt no "
"code point " "code point "
"specified"); "specified");
code = next_token(&value, ":"); code = strtok_r(value, ":", &last);
save_opt(query, code, value); save_opt(query, code, value);
break; break;
default: default:
@@ -1755,7 +1740,6 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv)
char *bargv[64]; char *bargv[64];
int rc; int rc;
char **rv; char **rv;
char *input;
isc_boolean_t global = ISC_TRUE; isc_boolean_t global = ISC_TRUE;
/* /*
@@ -1868,15 +1852,15 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv)
fatal("couldn't open batch file '%s'", batchname); fatal("couldn't open batch file '%s'", batchname);
} }
while (fgets(batchline, sizeof(batchline), batchfp) != 0) { while (fgets(batchline, sizeof(batchline), batchfp) != 0) {
bargc = 1; char *last;
if (batchline[0] == '\r' || batchline[0] == '\n' if (batchline[0] == '\r' || batchline[0] == '\n'
|| batchline[0] == '#' || batchline[0] == ';') || batchline[0] == '#' || batchline[0] == ';')
continue; continue;
input = batchline; for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
bargv[bargc] = next_token(&input, " \t\r\n"); (bargc < 14) && bargv[bargc];
while ((bargc < 14) && (bargv[bargc] != NULL)) { bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last))
bargc++; {
bargv[bargc] = next_token(&input, " \t\r\n"); /* empty body */
} }
bargv[0] = argv[0]; bargv[0] = argv[0];

31
configure vendored
View File

@@ -747,7 +747,6 @@ ISC_PLATFORM_NEEDSTRLCPY
GENRANDOMLIB GENRANDOMLIB
ISC_PLATFORM_NEEDSTRTOUL ISC_PLATFORM_NEEDSTRTOUL
ISC_PLATFORM_NEEDMEMMOVE ISC_PLATFORM_NEEDMEMMOVE
ISC_PLATFORM_NEEDSTRSEP
ISC_IRS_GETNAMEINFOSOCKLEN ISC_IRS_GETNAMEINFOSOCKLEN
ISC_IRS_NEEDADDRINFO ISC_IRS_NEEDADDRINFO
ISC_PLATFORM_HAVETFO ISC_PLATFORM_HAVETFO
@@ -19429,36 +19428,6 @@ esac
# Check for some other useful functions that are not ever-present. # Check for some other useful functions that are not ever-present.
# #
# We test for strsep() using AC_TRY_LINK instead of AC_CHECK_FUNC
# because AIX 4.3.3 with patches for bos.adt.include to version 4.3.3.77
# reportedly defines strsep() without declaring it in <string.h> when
# -D_LINUX_SOURCE_COMPAT is not defined [RT #2190], and
# AC_CHECK_FUNC() incorrectly succeeds because it declares
# the function itself.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for correctly declared strsep()" >&5
$as_echo_n "checking for correctly declared strsep()... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <string.h>
int
main ()
{
char *sp; char *foo = strsep(&sp, ".");
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }; ISC_PLATFORM_NEEDSTRSEP="#undef ISC_PLATFORM_NEEDSTRSEP"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }; ISC_PLATFORM_NEEDSTRSEP="#define ISC_PLATFORM_NEEDSTRSEP 1"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
ac_fn_c_check_func "$LINENO" "memmove" "ac_cv_func_memmove" ac_fn_c_check_func "$LINENO" "memmove" "ac_cv_func_memmove"
if test "x$ac_cv_func_memmove" = xyes; then : if test "x$ac_cv_func_memmove" = xyes; then :
ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE" ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"

View File

@@ -3492,18 +3492,6 @@ esac
# Check for some other useful functions that are not ever-present. # Check for some other useful functions that are not ever-present.
# #
# We test for strsep() using AC_TRY_LINK instead of AC_CHECK_FUNC
# because AIX 4.3.3 with patches for bos.adt.include to version 4.3.3.77
# reportedly defines strsep() without declaring it in <string.h> when
# -D_LINUX_SOURCE_COMPAT is not defined [RT #2190], and
# AC_CHECK_FUNC() incorrectly succeeds because it declares
# the function itself.
AC_MSG_CHECKING(for correctly declared strsep())
AC_TRY_LINK([#include <string.h>], [char *sp; char *foo = strsep(&sp, ".");],
[AC_MSG_RESULT(yes); ISC_PLATFORM_NEEDSTRSEP="#undef ISC_PLATFORM_NEEDSTRSEP"],
[AC_MSG_RESULT(no); ISC_PLATFORM_NEEDSTRSEP="#define ISC_PLATFORM_NEEDSTRSEP 1"])
AC_SUBST(ISC_PLATFORM_NEEDSTRSEP)
AC_CHECK_FUNC(memmove, AC_CHECK_FUNC(memmove,
[ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"], [ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"],
[ISC_PLATFORM_NEEDMEMMOVE="#define ISC_PLATFORM_NEEDMEMMOVE 1"]) [ISC_PLATFORM_NEEDMEMMOVE="#define ISC_PLATFORM_NEEDMEMMOVE 1"])

View File

@@ -286,47 +286,24 @@ quit(1);
int int
getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) { getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
char *tmp; char *token, *last;
char *left;
char *right;
int result=0;
UNUSED(dbp); UNUSED(dbp);
UNUSED(pkey); UNUSED(pkey);
/* Allocate memory to use in parsing the string */ if ((token = strtok_r(pdata->data, " ", &last)) == NULL) {
tmp = right = malloc(pdata->size + 1); return BDBparseErr;
}
/* verify memory was allocated */
if (right == NULL) {
result = BDBparseErr;
goto getzone_cleanup;
}
/* copy data string into newly allocated memory */
strncpy(right, pdata->data, pdata->size);
right[pdata->size] = '\0';
/* split string at the first space */
left = isc_string_separate(&right, " ");
/* copy string for "zone" secondary index */ /* copy string for "zone" secondary index */
skey->data = strdup(left); if ((skey->data = strdup(token)) == NULL) {
if (skey->data == NULL) { return BDBparseErr;
result = BDBparseErr;
goto getzone_cleanup;
} }
/* set required values for BDB */ /* set required values for BDB */
skey->size = strlen(skey->data); skey->size = strlen(skey->data);
skey->flags = DB_DBT_APPMALLOC; skey->flags = DB_DBT_APPMALLOC;
getzone_cleanup: return 0;
/* cleanup memory */
if (tmp != NULL)
free(tmp);
return result;
} }
/*% /*%
@@ -335,56 +312,30 @@ getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
int int
gethost(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) { gethost(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
char *tmp; char *token, *last;
char *left;
char *right;
int result=0;
UNUSED(dbp); UNUSED(dbp);
UNUSED(pkey); UNUSED(pkey);
/* allocate memory to use in parsing the string */ /* we don't care about first token. */
tmp = right = malloc(pdata->size + 1); if ((token = strtok_r(right, " ", &last)) == NULL) {
return BDBparseErr;
/* verify memory was allocated */
if (tmp == NULL) {
result = BDBparseErr;
goto gethost_cleanup;
}
/* copy data string into newly allocated memory */
strncpy(right, pdata->data, pdata->size);
right[pdata->size] = '\0';
/* we don't care about left string. */
/* memory of left string will be freed when tmp is freed. */
isc_string_separate(&right, " ");
/* verify right still has some characters left */
if (right == NULL) {
result = BDBparseErr;
goto gethost_cleanup;
} }
/* get "host" from data string */ /* get "host" from data string */
left = isc_string_separate(&right, " "); if ((token = strtok_r(NULL, " ", &last)) == NULL) {
return BDBparseErr;
}
/* copy string for "host" secondary index */ /* copy string for "host" secondary index */
skey->data = strdup(left); if ((skey->data = strdup(token)) == NULL) {
if (skey->data == NULL) { return BDBparseErr;
result = BDBparseErr;
goto gethost_cleanup;
} }
/* set required values for BDB */ /* set required values for BDB */
skey->size = strlen(skey->data); skey->size = strlen(skey->data);
skey->flags = DB_DBT_APPMALLOC; skey->flags = DB_DBT_APPMALLOC;
gethost_cleanup: return 0;
/* cleanup memory */
if (tmp != NULL)
free(tmp);
return result;
} }
/*% /*%

View File

@@ -158,9 +158,9 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
* split string at the first "$". set query segment to * split string at the first "$". set query segment to
* left portion * left portion
*/ */
char *last = NULL;
tseg->sql = isc_mem_strdup(mctx, tseg->sql = isc_mem_strdup(mctx,
isc_string_separate(&right_str, strtok_r(right_str, "$", &last));
"$"));
if (tseg->sql == NULL) { if (tseg->sql == NULL) {
/* no memory, clean everything up. */ /* no memory, clean everything up. */
result = ISC_R_NOMEMORY; result = ISC_R_NOMEMORY;

View File

@@ -132,14 +132,16 @@ build_querylist(const char *query_str, char **zone, char **record,
} }
/* loop through the string and chop it up */ /* loop through the string and chop it up */
while (right_str != NULL) { for (token = strtok_r(right_str, "$", &temp_str);
token;
token = strtok_r(NULL, "$", &temp_str))
{
/* allocate memory for tseg */ /* allocate memory for tseg */
tseg = calloc(1, sizeof(query_segment_t)); tseg = calloc(1, sizeof(query_segment_t));
if (tseg == NULL) { /* no memory, clean everything up. */ if (tseg == NULL) { /* no memory, clean everything up. */
result = ISC_R_NOMEMORY; result = ISC_R_NOMEMORY;
goto cleanup; goto cleanup;
} }
tseg->cmd = NULL;
tseg->direct = ISC_FALSE; tseg->direct = ISC_FALSE;
/* initialize the query segment link */ /* initialize the query segment link */
DLZ_LINK_INIT(tseg, link); DLZ_LINK_INIT(tseg, link);
@@ -150,7 +152,7 @@ build_querylist(const char *query_str, char **zone, char **record,
* split string at the first "$". set query segment to * split string at the first "$". set query segment to
* left portion * left portion
*/ */
tseg->cmd = strdup(strsep(&right_str, "$")); tseg->cmd = strdup(token);
if (tseg->cmd == NULL) { if (tseg->cmd == NULL) {
/* no memory, clean everything up. */ /* no memory, clean everything up. */
result = ISC_R_NOMEMORY; result = ISC_R_NOMEMORY;
@@ -203,7 +205,8 @@ build_querylist(const char *query_str, char **zone, char **record,
} }
/* we don't need temp_str any more */ /* we don't need temp_str any more */
free(temp_str); free(right_str);
right_str = NULL;
/* /*
* add checks later to verify zone and record are found if * add checks later to verify zone and record are found if
* necessary. * necessary.
@@ -246,8 +249,9 @@ build_querylist(const char *query_str, char **zone, char **record,
cleanup: cleanup:
/* get rid of temp_str */ /* get rid of temp_str */
if (temp_str != NULL) if (right_str != NULL) {
free(temp_str); free(right_str);
}
flag_fail: flag_fail:
/* get rid of what was build of the query list */ /* get rid of what was build of the query list */

View File

@@ -1051,29 +1051,6 @@ resolve_name(int family, const char *hostname, int flags,
return (error); return (error);
} }
static char *
irs_strsep(char **stringp, const char *delim) {
char *string = *stringp;
char *s;
const char *d;
char sc, dc;
if (string == NULL)
return (NULL);
for (s = string; *s != '\0'; s++) {
sc = *s;
for (d = delim; (dc = *d) != '\0'; d++)
if (sc == dc) {
*s++ = '\0';
*stringp = s;
return (string);
}
}
*stringp = NULL;
return (string);
}
static void static void
set_order(int family, int (**net_order)(const char *, int, struct addrinfo **, set_order(int family, int (**net_order)(const char *, int, struct addrinfo **,
int, int)) int, int))
@@ -1093,19 +1070,21 @@ set_order(int family, int (**net_order)(const char *, int, struct addrinfo **,
} else { } else {
order = getenv("NET_ORDER"); order = getenv("NET_ORDER");
found = 0; found = 0;
while (order != NULL) { char *last;
/* for (tok = strtok_r(order, ":", &last);
* We ignore any unknown names. tok;
*/ tok = strtok_r(NULL, ":", &last))
tok = irs_strsep(&order, ":"); {
if (strcasecmp(tok, "inet6") == 0) { if (strcasecmp(tok, "inet6") == 0) {
if ((found & FOUND_IPV6) == 0) if ((found & FOUND_IPV6) == 0) {
*net_order++ = add_ipv6; *net_order++ = add_ipv6;
}
found |= FOUND_IPV6; found |= FOUND_IPV6;
} else if (strcasecmp(tok, "inet") == 0 || } else if (strcasecmp(tok, "inet") == 0 ||
strcasecmp(tok, "inet4") == 0) { strcasecmp(tok, "inet4") == 0) {
if ((found & FOUND_IPV4) == 0) if ((found & FOUND_IPV4) == 0) {
*net_order++ = add_ipv4; *net_order++ = add_ipv4;
}
found |= FOUND_IPV4; found |= FOUND_IPV4;
} }
} }

View File

@@ -183,14 +183,6 @@
*/ */
@ISC_PLATFORM_QUADFORMAT@ @ISC_PLATFORM_QUADFORMAT@
/***
*** String functions.
***/
/*
* If the system needs strsep(), ISC_PLATFORM_NEEDSTRSEP will be defined.
*/
@ISC_PLATFORM_NEEDSTRSEP@
/* /*
* If the system needs strlcpy(), ISC_PLATFORM_NEEDSTRLCPY will be defined. * If the system needs strlcpy(), ISC_PLATFORM_NEEDSTRLCPY will be defined.
*/ */

View File

@@ -32,13 +32,6 @@
ISC_LANG_BEGINDECLS ISC_LANG_BEGINDECLS
char *
isc_string_separate(char **stringp, const char *delim);
#ifdef ISC_PLATFORM_NEEDSTRSEP
#define strsep isc_string_separate
#endif
#ifdef ISC_PLATFORM_NEEDMEMMOVE #ifdef ISC_PLATFORM_NEEDMEMMOVE
#define memmove(a,b,c) bcopy(b,a,c) #define memmove(a,b,c) bcopy(b,a,c)
#endif #endif

View File

@@ -50,27 +50,6 @@
#include <isc/string.h> #include <isc/string.h>
#include <isc/util.h> #include <isc/util.h>
char *
isc_string_separate(char **stringp, const char *delim) {
char *string = *stringp;
char *s;
const char *d;
char sc, dc;
if (string == NULL)
return (NULL);
for (s = string; (sc = *s) != '\0'; s++)
for (d = delim; (dc = *d) != '\0'; d++)
if (sc == dc) {
*s++ = '\0';
*stringp = s;
return (string);
}
*stringp = NULL;
return (string);
}
size_t size_t
isc_string_strlcpy(char *dst, const char *src, size_t size) isc_string_strlcpy(char *dst, const char *src, size_t size)
{ {

View File

@@ -645,7 +645,6 @@ isc_stdio_sync
isc_stdio_tell isc_stdio_tell
isc_stdio_write isc_stdio_write
isc_stdtime_get isc_stdtime_get
isc_string_separate
isc_string_strcasestr isc_string_strcasestr
isc_string_strlcat isc_string_strlcat
isc_string_strlcpy isc_string_strlcpy