2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

Merge branch '178-cleanup-isc-string' into 'master'

Cleanup <isc/string.h> functions

See merge request isc-projects/bind9!163
This commit is contained in:
Witold Krecicki 2018-04-12 04:46:09 -04:00
commit 717a4eb6e1
36 changed files with 294 additions and 893 deletions

View File

@ -1,3 +1,6 @@
4924. [cleanup] Clean up the isc_string_* namespace and leave
only strlcpy and strlcat. [GL #178]
4923. [cleanup] Refactor socket and socket event options into
enum types. [GL !135]

View File

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

View File

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

View File

@ -242,18 +242,6 @@ check_next_lookup(dig_lookup_t *lookup);
static isc_boolean_t
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
count_dots(char *string) {
char *s;

View File

@ -369,9 +369,6 @@ destroy_libs(void);
void
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
* then assigned to the appropriate function pointer

View File

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

View File

@ -470,6 +470,7 @@ parse_command_line(int argc, char *argv[]) {
int ch;
int port;
const char *p;
char *last;
save_command_line(argc, argv);
@ -607,14 +608,14 @@ parse_command_line(int argc, char *argv[]) {
else if (!strncmp(isc_commandline_argument,
"mkeytimers=", 11))
{
p = strtok(isc_commandline_argument + 11, "/");
p = strtok_r(isc_commandline_argument + 11, "/", &last);
if (p == NULL)
named_main_earlyfatal("bad mkeytimer");
dns_zone_mkey_hour = atoi(p);
if (dns_zone_mkey_hour == 0)
named_main_earlyfatal("bad mkeytimer");
p = strtok(NULL, "/");
p = strtok_r(NULL, "/", &last);
if (p == NULL) {
dns_zone_mkey_day =
(24 * dns_zone_mkey_hour);
@ -626,7 +627,7 @@ parse_command_line(int argc, char *argv[]) {
if (dns_zone_mkey_day < dns_zone_mkey_hour)
named_main_earlyfatal("bad mkeytimer");
p = strtok(NULL, "/");
p = strtok_r(NULL, "/", &last);
if (p == NULL) {
dns_zone_mkey_month =
(30 * dns_zone_mkey_day);

View File

@ -3106,6 +3106,7 @@ render_xsl(const char *url, isc_httpdurl_t *urlinfo,
isc_httpdfree_t **freecb, void **freecb_args)
{
isc_result_t result;
char *_headers = NULL;
UNUSED(url);
UNUSED(querystring);
@ -3117,30 +3118,39 @@ render_xsl(const char *url, isc_httpdurl_t *urlinfo,
if (urlinfo->isstatic) {
isc_time_t when;
char *p = strcasestr(headers, "If-Modified-Since: ");
char *line, *saveptr;
const char *if_modified_since = "If-Modified-Since: ";
_headers = strdup(headers);
if (p != NULL) {
time_t t1, t2;
p += strlen("If-Modified-Since: ");
result = isc_time_parsehttptimestamp(p, &when);
if (result != ISC_R_SUCCESS)
goto send;
for (line = strtok_r(_headers, "\n", &saveptr);
line;
line = strtok_r(NULL, "\n", &saveptr)) {
if (strncasecmp(line, if_modified_since, strlen(if_modified_since)) == 0) {
time_t t1, t2;
line += strlen(if_modified_since);
result = isc_time_parsehttptimestamp(line, &when);
if (result != ISC_R_SUCCESS) {
goto send;
}
result = isc_time_secondsastimet(&when, &t1);
if (result != ISC_R_SUCCESS)
goto send;
result = isc_time_secondsastimet(&when, &t1);
if (result != ISC_R_SUCCESS) {
goto send;
}
result = isc_time_secondsastimet(&urlinfo->loadtime,
&t2);
if (result != ISC_R_SUCCESS)
goto send;
result = isc_time_secondsastimet(&urlinfo->loadtime, &t2);
if (result != ISC_R_SUCCESS) {
goto send;
}
if (t1 < t2)
goto send;
if (t1 < t2) {
goto send;
}
*retcode = 304;
*retmsg = "Not modified";
return (ISC_R_SUCCESS);
*retcode = 304;
*retmsg = "Not modified";
goto end;
}
}
}
@ -3149,7 +3159,8 @@ render_xsl(const char *url, isc_httpdurl_t *urlinfo,
*retmsg = "OK";
isc_buffer_reinit(b, xslmsg, strlen(xslmsg));
isc_buffer_add(b, strlen(xslmsg));
end:
free(_headers);
return (ISC_R_SUCCESS);
}

View File

@ -1003,36 +1003,24 @@ named_os_gethostname(char *buf, size_t len) {
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
named_os_shutdownmsg(char *command, isc_buffer_t *text) {
char *input, *ptr;
char *last, *ptr;
pid_t pid;
input = command;
/* Skip the command name. */
ptr = next_token(&input, " \t");
if (ptr == NULL)
if ((ptr = strtok_r(command, " \t", &last)) == NULL) {
return;
}
ptr = next_token(&input, " \t");
if (ptr == NULL)
if ((ptr = strtok_r(NULL, " \t", &last)) == NULL) {
return;
}
if (strcmp(ptr, "-p") != 0)
if (strcmp(ptr, "-p") != 0) {
return;
}
#ifdef HAVE_LINUXTHREADS
pid = mainpid;

View File

@ -2910,33 +2910,31 @@ start_gssrequest(dns_name_t *master) {
if (realm == NULL)
get_ticket_realm(gmctx);
result = isc_string_printf(servicename, sizeof(servicename),
"DNS/%s%s", namestr, realm ? realm : "");
if (result != ISC_R_SUCCESS)
fatal("isc_string_printf(servicename) failed: %s",
isc_result_totext(result));
result = snprintf(servicename, sizeof(servicename), "DNS/%s%s", namestr, realm ? realm : "");
RUNTIME_CHECK(result < sizeof(servicename));
isc_buffer_init(&buf, servicename, strlen(servicename));
isc_buffer_add(&buf, strlen(servicename));
result = dns_name_fromtext(servname, &buf, dns_rootname, 0, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("dns_name_fromtext(servname) failed: %s",
isc_result_totext(result));
}
keyname = dns_fixedname_initname(&fkname);
isc_random_get(&val);
result = isc_string_printf(mykeystr, sizeof(mykeystr), "%u.sig-%s",
val, namestr);
if (result != ISC_R_SUCCESS)
fatal("isc_string_printf(mykeystr) failed: %s",
isc_result_totext(result));
result = snprintf(mykeystr, sizeof(mykeystr), "%u.sig-%s", val, namestr);
RUNTIME_CHECK(result <= sizeof(mykeystr));
isc_buffer_init(&buf, mykeystr, strlen(mykeystr));
isc_buffer_add(&buf, strlen(mykeystr));
result = dns_name_fromtext(keyname, &buf, dns_rootname, 0, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("dns_name_fromtext(keyname) failed: %s",
isc_result_totext(result));
}
/* Windows doesn't recognize name compression in the key name. */
keyname->attributes |= DNS_NAMEATTR_NOCOMPRESS;

View File

@ -31,14 +31,6 @@
#include "driver.h"
#ifdef WIN32
#define STRTOK_R(a, b, c) strtok_s(a, b, c)
#elif defined(_REENTRANT)
#define STRTOK_R(a, b, c) strtok_r(a, b, c)
#else
#define STRTOK_R(a, b, c) strtok(a, b)
#endif
#define CHECK(x) \
do { \
result = (x); \
@ -726,23 +718,23 @@ modrdataset(struct dlz_example_data *state, const char *name,
* for the type used by dig
*/
full_name = STRTOK_R(buf, "\t", &saveptr);
full_name = strtok_r(buf, "\t", &saveptr);
if (full_name == NULL)
goto error;
ttlstr = STRTOK_R(NULL, "\t", &saveptr);
ttlstr = strtok_r(NULL, "\t", &saveptr);
if (ttlstr == NULL)
goto error;
dclass = STRTOK_R(NULL, "\t", &saveptr);
dclass = strtok_r(NULL, "\t", &saveptr);
if (dclass == NULL)
goto error;
type = STRTOK_R(NULL, "\t", &saveptr);
type = strtok_r(NULL, "\t", &saveptr);
if (type == NULL)
goto error;
data = STRTOK_R(NULL, "\t", &saveptr);
data = strtok_r(NULL, "\t", &saveptr);
if (data == NULL)
goto error;

View File

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

31
configure vendored
View File

@ -747,7 +747,6 @@ ISC_PLATFORM_NEEDSTRLCPY
GENRANDOMLIB
ISC_PLATFORM_NEEDSTRTOUL
ISC_PLATFORM_NEEDMEMMOVE
ISC_PLATFORM_NEEDSTRSEP
ISC_IRS_GETNAMEINFOSOCKLEN
ISC_IRS_NEEDADDRINFO
ISC_PLATFORM_HAVETFO
@ -19429,36 +19428,6 @@ esac
# 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"
if test "x$ac_cv_func_memmove" = xyes; then :
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.
#
# 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,
[ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"],
[ISC_PLATFORM_NEEDMEMMOVE="#define ISC_PLATFORM_NEEDMEMMOVE 1"])

View File

@ -286,47 +286,24 @@ quit(1);
int
getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
char *tmp;
char *left;
char *right;
int result=0;
char *token, *last;
UNUSED(dbp);
UNUSED(pkey);
/* Allocate memory to use in parsing the string */
tmp = right = malloc(pdata->size + 1);
/* 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, " ");
if ((token = strtok_r(pdata->data, " ", &last)) == NULL) {
return BDBparseErr;
}
/* copy string for "zone" secondary index */
skey->data = strdup(left);
if (skey->data == NULL) {
result = BDBparseErr;
goto getzone_cleanup;
if ((skey->data = strdup(token)) == NULL) {
return BDBparseErr;
}
/* set required values for BDB */
skey->size = strlen(skey->data);
skey->flags = DB_DBT_APPMALLOC;
getzone_cleanup:
/* cleanup memory */
if (tmp != NULL)
free(tmp);
return result;
return 0;
}
/*%
@ -335,56 +312,30 @@ getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
int
gethost(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
char *tmp;
char *left;
char *right;
int result=0;
char *token, *last;
UNUSED(dbp);
UNUSED(pkey);
/* allocate memory to use in parsing the string */
tmp = right = malloc(pdata->size + 1);
/* 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;
/* we don't care about first token. */
if ((token = strtok_r(right, " ", &last)) == NULL) {
return BDBparseErr;
}
/* 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 */
skey->data = strdup(left);
if (skey->data == NULL) {
result = BDBparseErr;
goto gethost_cleanup;
if ((skey->data = strdup(token)) == NULL) {
return BDBparseErr;
}
/* set required values for BDB */
skey->size = strlen(skey->data);
skey->flags = DB_DBT_APPMALLOC;
gethost_cleanup:
/* cleanup memory */
if (tmp != NULL)
free(tmp);
return result;
return 0;
}
/*%

View File

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

View File

@ -27,14 +27,6 @@
#include "../modules/include/dlz_minimal.h"
#ifdef WIN32
#define STRTOK_R(a, b, c) strtok_s(a, b, c)
#elif defined(_REENTRANT)
#define STRTOK_R(a, b, c) strtok_r(a, b, c)
#else
#define STRTOK_R(a, b, c) strtok(a, b)
#endif
#define CHECK(x) \
do { \
result = (x); \
@ -675,23 +667,23 @@ modrdataset(struct dlz_example_data *state, const char *name,
* for the type used by dig
*/
full_name = STRTOK_R(buf, "\t", &saveptr);
full_name = strtok_r(buf, "\t", &saveptr);
if (full_name == NULL)
goto error;
ttlstr = STRTOK_R(NULL, "\t", &saveptr);
ttlstr = strtok_r(NULL, "\t", &saveptr);
if (ttlstr == NULL)
goto error;
dclass = STRTOK_R(NULL, "\t", &saveptr);
dclass = strtok_r(NULL, "\t", &saveptr);
if (dclass == NULL)
goto error;
type = STRTOK_R(NULL, "\t", &saveptr);
type = strtok_r(NULL, "\t", &saveptr);
if (type == NULL)
goto error;
data = STRTOK_R(NULL, "\t", &saveptr);
data = strtok_r(NULL, "\t", &saveptr);
if (data == NULL)
goto error;

View File

@ -132,14 +132,16 @@ build_querylist(const char *query_str, char **zone, char **record,
}
/* 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 */
tseg = calloc(1, sizeof(query_segment_t));
if (tseg == NULL) { /* no memory, clean everything up. */
result = ISC_R_NOMEMORY;
goto cleanup;
}
tseg->cmd = NULL;
tseg->direct = ISC_FALSE;
/* initialize the query segment 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
* left portion
*/
tseg->cmd = strdup(strsep(&right_str, "$"));
tseg->cmd = strdup(token);
if (tseg->cmd == NULL) {
/* no memory, clean everything up. */
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 */
free(temp_str);
free(right_str);
right_str = NULL;
/*
* add checks later to verify zone and record are found if
* necessary.
@ -246,8 +249,9 @@ build_querylist(const char *query_str, char **zone, char **record,
cleanup:
/* get rid of temp_str */
if (temp_str != NULL)
free(temp_str);
if (right_str != NULL) {
free(right_str);
}
flag_fail:
/* get rid of what was build of the query list */

View File

@ -179,14 +179,6 @@
"DELETE FROM ZoneData WHERE zone_id = %s AND " \
"LOWER(name) = LOWER('%s') AND UPPER(type) = UPPER('%s')"
#ifdef WIN32
#define STRTOK_R(a, b, c) strtok_s(a, b, c)
#elif defined(_REENTRANT)
#define STRTOK_R(a, b, c) strtok_r(a, b, c)
#else
#define STRTOK_R(a, b, c) strtok(a, b)
#endif
/*
* Number of concurrent database connections we support
* - equivalent to maxmium number of concurrent transactions
@ -837,23 +829,23 @@ makerecord(mysql_data_t *state, const char *name, const char *rdatastr) {
* The DATA field is space separated, and is in the data format
* for the type used by dig
*/
real_name = STRTOK_R(buf, "\t", &saveptr);
real_name = strtok_r(buf, "\t", &saveptr);
if (real_name == NULL)
goto error;
ttlstr = STRTOK_R(NULL, "\t", &saveptr);
ttlstr = strtok_r(NULL, "\t", &saveptr);
if (ttlstr == NULL || sscanf(ttlstr, "%d", &ttlvalue) != 1)
goto error;
dclass = STRTOK_R(NULL, "\t", &saveptr);
dclass = strtok_r(NULL, "\t", &saveptr);
if (dclass == NULL)
goto error;
type = STRTOK_R(NULL, "\t", &saveptr);
type = strtok_r(NULL, "\t", &saveptr);
if (type == NULL)
goto error;
data = STRTOK_R(NULL, "\t", &saveptr);
data = strtok_r(NULL, "\t", &saveptr);
if (data == NULL)
goto error;

View File

@ -1184,7 +1184,7 @@ identify_directive(char *dir) {
*/
void
update_config(char *config_change_desc) {
char *directive, *config_value, *trailing_garbage;
char *directive, *config_value, *trailing_garbage, *last;
char conf_copy[MAX_INPUT_LEN + 1];
unsigned int uint_val;
int directive_number;
@ -1213,9 +1213,9 @@ update_config(char *config_change_desc) {
return;
}
directive = strtok(config_change_desc, WHITESPACE);
config_value = strtok(NULL, WHITESPACE);
trailing_garbage = strtok(NULL, WHITESPACE);
directive = strtok_r(config_change_desc, WHITESPACE, &last);
config_value = strtok_r(NULL, WHITESPACE, &last);
trailing_garbage = strtok_r(NULL, WHITESPACE, &last);
if ((directive_number = identify_directive(directive)) == -1) {
fprintf(stderr, "Invalid config: Bad directive: %s\n",
@ -1349,7 +1349,7 @@ parse_query(char *input, char *qname, unsigned int qnlen, int *qtype) {
unsigned int num_types, index;
int found = FALSE;
char incopy[MAX_INPUT_LEN + 1];
char *domain_str, *type_str;
char *domain_str, *type_str, *last;
num_types = sizeof(qtype_strings) / sizeof(qtype_strings[0]);
if (num_types > (sizeof(qtype_codes) / sizeof(int)))
@ -1357,8 +1357,8 @@ parse_query(char *input, char *qname, unsigned int qnlen, int *qtype) {
strcpy(incopy, input);
domain_str = strtok(incopy, WHITESPACE);
type_str = strtok(NULL, WHITESPACE);
domain_str = strtok_r(incopy, WHITESPACE, &last);
type_str = strtok_r(NULL, WHITESPACE, &last);
if ((domain_str == NULL) || (type_str == NULL)) {
fprintf(stderr, "Invalid query input format: %s\n", input);

View File

@ -113,6 +113,7 @@ bdb_lookup(const char *zone, const char *name, void *dbdata,
isc_consttextregion_t ttltext;
DBC *c;
DBT key, data;
char *last;
UNUSED(zone);
#ifdef DNS_CLIENTINFO_VERSION
@ -139,10 +140,10 @@ bdb_lookup(const char *zone, const char *name, void *dbdata,
while (ret == 0) {
((char *)key.data)[key.size] = 0;
((char *)data.data)[data.size] = 0;
ttltext.base = strtok((char *)data.data, " ");
ttltext.base = strtok_r((char *)data.data, " ", &last);
ttltext.length = strlen(ttltext.base);
dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
type = strtok(NULL, " ");
type = strtok_r(NULL, " ", &last);
rdata = type + strlen(type) + 1;
if (dns_sdb_putrr(l, type, ttl, rdata) != ISC_R_SUCCESS) {
@ -185,12 +186,13 @@ bdb_allnodes(const char *zone, void *dbdata, dns_sdballnodes_t *n)
memset(&data, 0, sizeof(DBT));
while (c->c_get(c, &key, &data, DB_NEXT) == 0) {
char *last;
((char *)key.data)[key.size] = 0;
((char *)data.data)[data.size] = 0;
ttltext.base = strtok((char *)data.data, " ");
ttltext.base = strtok_r((char *)data.data, " ", &last);
ttltext.length = strlen(ttltext.base);
dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
type = strtok(NULL, " ");
type = strtok_r(NULL, " ", &last);
rdata = type + strlen(type) + 1;
if (dns_sdb_putnamedrr(n, key.data, type, ttl, rdata) !=

View File

@ -705,10 +705,11 @@ dns_journal_open(isc_mem_t *mctx, const char *filename, unsigned int mode,
if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0)
namelen -= 4;
result = isc_string_printf(backup, sizeof(backup), "%.*s.jbk",
(int)namelen, filename);
if (result != ISC_R_SUCCESS)
return (result);
result = snprintf(backup, sizeof(backup), "%.*s.jbk",
(int)namelen, filename);
if (result >= sizeof(backup)) {
return ISC_R_NOSPACE;
}
result = journal_open(mctx, backup, writable, writable,
journalp);
}
@ -2100,25 +2101,24 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
unsigned int size = 0;
isc_result_t result;
unsigned int indexend;
char newname[1024];
char backup[1024];
char newname[PATH_MAX];
char backup[PATH_MAX];
isc_boolean_t is_backup = ISC_FALSE;
REQUIRE(filename != NULL);
namelen = strlen(filename);
if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0)
if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0) {
namelen -= 4;
}
result = isc_string_printf(newname, sizeof(newname), "%.*s.jnw",
(int)namelen, filename);
if (result != ISC_R_SUCCESS)
return (result);
result = snprintf(newname, sizeof(newname), "%.*s.jnw",
(int)namelen, filename);
RUNTIME_CHECK(result < sizeof(newname));
result = isc_string_printf(backup, sizeof(backup), "%.*s.jbk",
(int)namelen, filename);
if (result != ISC_R_SUCCESS)
return (result);
result = snprintf(backup, sizeof(backup), "%.*s.jbk",
(int)namelen, filename);
RUNTIME_CHECK(result < sizeof(backup));
result = journal_open(mctx, filename, ISC_FALSE, ISC_FALSE, &j1);
if (result == ISC_R_NOTFOUND) {

View File

@ -52,7 +52,7 @@ fromtext_any_tsig(ARGS_FROMTEXT) {
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
ISC_FALSE));
sigtime = isc_string_touint64(DNS_AS_STR(token), &e, 10);
sigtime = strtoull(DNS_AS_STR(token), &e, 10);
if (*e != 0)
RETTOK(DNS_R_SYNTAX);
if ((sigtime >> 48) != 0)

View File

@ -258,37 +258,37 @@ reverse_from_address(dns_name_t *tcpself, const isc_netaddr_t *tcpaddr) {
switch (tcpaddr->family) {
case AF_INET:
l = ntohl(tcpaddr->type.in.s_addr);
result = isc_string_printf(buf, sizeof(buf),
"%lu.%lu.%lu.%lu.IN-ADDR.ARPA.",
(l >> 0) & 0xff, (l >> 8) & 0xff,
(l >> 16) & 0xff, (l >> 24) & 0xff);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
result = snprintf(buf, sizeof(buf),
"%lu.%lu.%lu.%lu.IN-ADDR.ARPA.",
(l >> 0) & 0xff, (l >> 8) & 0xff,
(l >> 16) & 0xff, (l >> 24) & 0xff);
RUNTIME_CHECK(result < sizeof(buf));
break;
case AF_INET6:
ap = tcpaddr->type.in6.s6_addr;
result = isc_string_printf(buf, sizeof(buf),
"%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.%x.%x.%x.%x."
"IP6.ARPA.",
ap[15] & 0x0f, (ap[15] >> 4) & 0x0f,
ap[14] & 0x0f, (ap[14] >> 4) & 0x0f,
ap[13] & 0x0f, (ap[13] >> 4) & 0x0f,
ap[12] & 0x0f, (ap[12] >> 4) & 0x0f,
ap[11] & 0x0f, (ap[11] >> 4) & 0x0f,
ap[10] & 0x0f, (ap[10] >> 4) & 0x0f,
ap[9] & 0x0f, (ap[9] >> 4) & 0x0f,
ap[8] & 0x0f, (ap[8] >> 4) & 0x0f,
ap[7] & 0x0f, (ap[7] >> 4) & 0x0f,
ap[6] & 0x0f, (ap[6] >> 4) & 0x0f,
ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
result = snprintf(buf, sizeof(buf),
"%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.%x.%x.%x.%x."
"IP6.ARPA.",
ap[15] & 0x0f, (ap[15] >> 4) & 0x0f,
ap[14] & 0x0f, (ap[14] >> 4) & 0x0f,
ap[13] & 0x0f, (ap[13] >> 4) & 0x0f,
ap[12] & 0x0f, (ap[12] >> 4) & 0x0f,
ap[11] & 0x0f, (ap[11] >> 4) & 0x0f,
ap[10] & 0x0f, (ap[10] >> 4) & 0x0f,
ap[9] & 0x0f, (ap[9] >> 4) & 0x0f,
ap[8] & 0x0f, (ap[8] >> 4) & 0x0f,
ap[7] & 0x0f, (ap[7] >> 4) & 0x0f,
ap[6] & 0x0f, (ap[6] >> 4) & 0x0f,
ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
RUNTIME_CHECK(result < sizeof(buf));
break;
default:
INSIST(0);
@ -310,27 +310,27 @@ stf_from_address(dns_name_t *stfself, const isc_netaddr_t *tcpaddr) {
switch(tcpaddr->family) {
case AF_INET:
l = ntohl(tcpaddr->type.in.s_addr);
result = isc_string_printf(buf, sizeof(buf),
"%lx.%lx.%lx.%lx.%lx.%lx.%lx.%lx"
"2.0.0.2.IP6.ARPA.",
l & 0xf, (l >> 4) & 0xf,
(l >> 8) & 0xf, (l >> 12) & 0xf,
(l >> 16) & 0xf, (l >> 20) & 0xf,
(l >> 24) & 0xf, (l >> 28) & 0xf);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
result = snprintf(buf, sizeof(buf),
"%lx.%lx.%lx.%lx.%lx.%lx.%lx.%lx"
"2.0.0.2.IP6.ARPA.",
l & 0xf, (l >> 4) & 0xf,
(l >> 8) & 0xf, (l >> 12) & 0xf,
(l >> 16) & 0xf, (l >> 20) & 0xf,
(l >> 24) & 0xf, (l >> 28) & 0xf);
RUNTIME_CHECK(result < sizeof(buf));
break;
case AF_INET6:
ap = tcpaddr->type.in6.s6_addr;
result = isc_string_printf(buf, sizeof(buf),
"%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.IP6.ARPA.",
ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
result = snprintf(buf, sizeof(buf),
"%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.IP6.ARPA.",
ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
RUNTIME_CHECK(result < sizeof(buf));
break;
default:
INSIST(0);

View File

@ -1051,34 +1051,11 @@ resolve_name(int family, const char *hostname, int flags,
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
set_order(int family, int (**net_order)(const char *, int, struct addrinfo **,
int, int))
{
char *order, *tok;
char *order, *tok, *last;
int found;
if (family) {
@ -1093,19 +1070,20 @@ set_order(int family, int (**net_order)(const char *, int, struct addrinfo **,
} else {
order = getenv("NET_ORDER");
found = 0;
while (order != NULL) {
/*
* We ignore any unknown names.
*/
tok = irs_strsep(&order, ":");
for (tok = strtok_r(order, ":", &last);
tok;
tok = strtok_r(NULL, ":", &last))
{
if (strcasecmp(tok, "inet6") == 0) {
if ((found & FOUND_IPV6) == 0)
if ((found & FOUND_IPV6) == 0) {
*net_order++ = add_ipv6;
}
found |= FOUND_IPV6;
} else if (strcasecmp(tok, "inet") == 0 ||
strcasecmp(tok, "inet4") == 0) {
if ((found & FOUND_IPV4) == 0)
strcasecmp(tok, "inet4") == 0) {
if ((found & FOUND_IPV4) == 0) {
*net_order++ = add_ipv4;
}
found |= FOUND_IPV4;
}
}

View File

@ -183,14 +183,6 @@
*/
@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.
*/

View File

@ -9,210 +9,24 @@
* information regarding copyright ownership.
*/
/* $Id: string.h,v 1.23 2007/09/13 04:48:16 each Exp $ */
#ifndef ISC_STRING_H
#define ISC_STRING_H 1
#pragma once
/*! \file isc/string.h */
#include <isc/formatcheck.h>
#include <isc/int.h>
#include <isc/lang.h>
#include <isc/platform.h>
#include <isc/types.h>
#include <string.h>
#ifdef ISC_PLATFORM_HAVESTRINGSH
#include <strings.h>
#endif
#define ISC_STRING_MAGIC 0x5e
#include "isc/platform.h"
#include "isc/lang.h"
ISC_LANG_BEGINDECLS
isc_uint64_t
isc_string_touint64(char *source, char **endp, int base);
/*%<
* Convert the string pointed to by 'source' to isc_uint64_t.
*
* On successful conversion 'endp' points to the first character
* after conversion is complete.
*
* 'base': 0 or 2..36
*
* If base is 0 the base is computed from the string type.
*
* On error 'endp' points to 'source'.
*/
isc_result_t
isc_string_copy(char *target, size_t size, const char *source);
/*
* Copy the string pointed to by 'source' to 'target' which is a
* pointer to a string of at least 'size' bytes.
*
* Requires:
* 'target' is a pointer to a char[] of at least 'size' bytes.
* 'size' an integer > 0.
* 'source' == NULL or points to a NUL terminated string.
*
* Ensures:
* If result == ISC_R_SUCCESS
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*
* If result == ISC_R_NOSPACE
* 'target' is undefined.
*
* Returns:
* ISC_R_SUCCESS -- 'source' was successfully copied to 'target'.
* ISC_R_NOSPACE -- 'source' could not be copied since 'target'
* is too small.
*/
void
isc_string_copy_truncate(char *target, size_t size, const char *source);
/*
* Copy the string pointed to by 'source' to 'target' which is a
* pointer to a string of at least 'size' bytes.
*
* Requires:
* 'target' is a pointer to a char[] of at least 'size' bytes.
* 'size' an integer > 0.
* 'source' == NULL or points to a NUL terminated string.
*
* Ensures:
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*/
isc_result_t
isc_string_append(char *target, size_t size, const char *source);
/*
* Append the string pointed to by 'source' to 'target' which is a
* pointer to a NUL terminated string of at least 'size' bytes.
*
* Requires:
* 'target' is a pointer to a NUL terminated char[] of at
* least 'size' bytes.
* 'size' an integer > 0.
* 'source' == NULL or points to a NUL terminated string.
*
* Ensures:
* If result == ISC_R_SUCCESS
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*
* If result == ISC_R_NOSPACE
* 'target' is undefined.
*
* Returns:
* ISC_R_SUCCESS -- 'source' was successfully appended to 'target'.
* ISC_R_NOSPACE -- 'source' could not be appended since 'target'
* is too small.
*/
void
isc_string_append_truncate(char *target, size_t size, const char *source);
/*
* Append the string pointed to by 'source' to 'target' which is a
* pointer to a NUL terminated string of at least 'size' bytes.
*
* Requires:
* 'target' is a pointer to a NUL terminated char[] of at
* least 'size' bytes.
* 'size' an integer > 0.
* 'source' == NULL or points to a NUL terminated string.
*
* Ensures:
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*/
isc_result_t
isc_string_printf(char *target, size_t size, const char *format, ...)
ISC_FORMAT_PRINTF(3, 4);
/*
* Print 'format' to 'target' which is a pointer to a string of at least
* 'size' bytes.
*
* Requires:
* 'target' is a pointer to a char[] of at least 'size' bytes.
* 'size' an integer > 0.
* 'format' == NULL or points to a NUL terminated string.
*
* Ensures:
* If result == ISC_R_SUCCESS
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*
* If result == ISC_R_NOSPACE
* 'target' is undefined.
*
* Returns:
* ISC_R_SUCCESS -- 'format' was successfully printed to 'target'.
* ISC_R_NOSPACE -- 'format' could not be printed to 'target' since it
* is too small.
*/
void
isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
ISC_FORMAT_PRINTF(3, 4);
/*
* Print 'format' to 'target' which is a pointer to a string of at least
* 'size' bytes.
*
* Requires:
* 'target' is a pointer to a char[] of at least 'size' bytes.
* 'size' an integer > 0.
* 'format' == NULL or points to a NUL terminated string.
*
* Ensures:
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*/
char *
isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source);
/*
* Copy the region pointed to by r to a NUL terminated string
* allocated from the memory context pointed to by mctx.
*
* The result should be deallocated using isc_mem_free()
*
* Requires:
* 'mctx' is a point to a valid memory context.
* 'source' is a pointer to a valid region.
*
* Returns:
* a pointer to a NUL terminated string or
* NULL if memory for the copy could not be allocated
*
*/
char *
isc_string_separate(char **stringp, const char *delim);
#ifdef ISC_PLATFORM_NEEDSTRSEP
#define strsep isc_string_separate
#endif
#ifdef ISC_PLATFORM_NEEDMEMMOVE
#define memmove(a,b,c) bcopy(b,a,c)
#endif
size_t
isc_string_strlcpy(char *dst, const char *src, size_t size);
#ifdef ISC_PLATFORM_NEEDSTRLCPY
#define strlcpy isc_string_strlcpy
#endif
size_t
isc_string_strlcat(char *dst, const char *src, size_t size);
@ -220,13 +34,4 @@ isc_string_strlcat(char *dst, const char *src, size_t size);
#define strlcat isc_string_strlcat
#endif
char *
isc_string_strcasestr(const char *big, const char *little);
#ifdef ISC_PLATFORM_NEEDSTRCASESTR
#define strcasestr isc_string_strcasestr
#endif
ISC_LANG_ENDDECLS
#endif /* ISC_STRING_H */

View File

@ -1280,8 +1280,7 @@ remove_old_tsversions(isc_logfile_t *file, int versions) {
dir.entry.name[bnamelen] == '.')
{
char *ename = &dir.entry.name[bnamelen + 1];
version = isc_string_touint64(ename,
&digit_end, 10);
version = strtoull(ename, &digit_end, 10);
if (*digit_end == '\0') {
int i = 0;
while (i < versions &&
@ -1316,7 +1315,7 @@ remove_old_tsversions(isc_logfile_t *file, int versions) {
dir.entry.name[bnamelen] == '.')
{
char *ename = &dir.entry.name[bnamelen + 1];
version = isc_string_touint64(ename, &digit_end, 10);
version = strtoull(ename, &digit_end, 10);
/*
* Remove any backup files that exceed versions.
*/

View File

@ -13,6 +13,8 @@
#include <config.h>
#include <stdlib.h>
#include <isc/string.h>
#include <isc/net.h>
#include <isc/netscope.h>
@ -47,7 +49,7 @@ isc_netscope_pton(int af, char *scopename, void *addr, isc_uint32_t *zoneid) {
zone = (isc_uint32_t)ifid;
else {
#endif
llz = isc_string_touint64(scopename, &ep, 10);
llz = strtoull(scopename, &ep, 10);
if (ep == scopename)
return (ISC_R_FAILURE);

View File

@ -40,202 +40,11 @@
/*! \file */
#include <config.h>
#include <config.h> // IWYU pragma: keep
#include <ctype.h>
#include <string.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/region.h>
#include <isc/string.h>
#include <isc/util.h>
static const char digits[] = "0123456789abcdefghijklmnoprstuvwxyz";
isc_uint64_t
isc_string_touint64(char *source, char **end, int base) {
isc_uint64_t tmp;
isc_uint64_t overflow;
char *s = source;
const char *o;
char c;
if ((base < 0) || (base == 1) || (base > 36)) {
*end = source;
return (0);
}
while (*s != 0 && isascii(*s&0xff) && isspace(*s&0xff))
s++;
if (*s == '+' /* || *s == '-' */)
s++;
if (base == 0) {
if (*s == '0' && (*(s+1) == 'X' || *(s+1) == 'x')) {
s += 2;
base = 16;
} else if (*s == '0')
base = 8;
else
base = 10;
}
if (*s == 0) {
*end = source;
return (0);
}
overflow = ~0;
overflow /= base;
tmp = 0;
while ((c = *s) != 0) {
c = tolower(c&0xff);
/* end ? */
if ((o = strchr(digits, c)) == NULL) {
*end = s;
return (tmp);
}
/* end ? */
if ((o - digits) >= base) {
*end = s;
return (tmp);
}
/* overflow ? */
if (tmp > overflow) {
*end = source;
return (0);
}
tmp *= base;
/* overflow ? */
if ((tmp + (o - digits)) < tmp) {
*end = source;
return (0);
}
tmp += o - digits;
s++;
}
*end = s;
return (tmp);
}
isc_result_t
isc_string_copy(char *target, size_t size, const char *source) {
REQUIRE(size > 0U);
if (strlcpy(target, source, size) >= size) {
memset(target, ISC_STRING_MAGIC, size);
return (ISC_R_NOSPACE);
}
ENSURE(strlen(target) < size);
return (ISC_R_SUCCESS);
}
void
isc_string_copy_truncate(char *target, size_t size, const char *source) {
REQUIRE(size > 0U);
strlcpy(target, source, size);
ENSURE(strlen(target) < size);
}
isc_result_t
isc_string_append(char *target, size_t size, const char *source) {
REQUIRE(size > 0U);
REQUIRE(strlen(target) < size);
if (strlcat(target, source, size) >= size) {
memset(target, ISC_STRING_MAGIC, size);
return (ISC_R_NOSPACE);
}
ENSURE(strlen(target) < size);
return (ISC_R_SUCCESS);
}
void
isc_string_append_truncate(char *target, size_t size, const char *source) {
REQUIRE(size > 0U);
REQUIRE(strlen(target) < size);
strlcat(target, source, size);
ENSURE(strlen(target) < size);
}
isc_result_t
isc_string_printf(char *target, size_t size, const char *format, ...) {
va_list args;
size_t n;
REQUIRE(size > 0U);
va_start(args, format);
n = vsnprintf(target, size, format, args);
va_end(args);
if (n >= size) {
memset(target, ISC_STRING_MAGIC, size);
return (ISC_R_NOSPACE);
}
ENSURE(strlen(target) < size);
return (ISC_R_SUCCESS);
}
void
isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
{
va_list args;
REQUIRE(size > 0U);
va_start(args, format);
/* check return code? */
(void)vsnprintf(target, size, format, args);
va_end(args);
ENSURE(strlen(target) < size);
}
char *
isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source) {
char *target;
REQUIRE(mctx != NULL);
REQUIRE(source != NULL);
target = (char *) isc_mem_allocate(mctx, source->length + 1);
if (target != NULL) {
memmove(source->base, target, source->length);
target[source->length] = '\0';
}
return (target);
}
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);
}
#include "isc/string.h" // IWYU pragma: keep
size_t
isc_string_strlcpy(char *dst, const char *src, size_t size)
@ -247,15 +56,17 @@ isc_string_strlcpy(char *dst, const char *src, size_t size)
/* Copy as many bytes as will fit */
if (n != 0U && --n != 0U) {
do {
if ((*d++ = *s++) == 0)
if ((*d++ = *s++) == 0) {
break;
}
} while (--n != 0U);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0U) {
if (size != 0U)
if (size != 0U) {
*d = '\0'; /* NUL-terminate dst */
}
while (*s++)
;
}
@ -272,13 +83,15 @@ isc_string_strlcat(char *dst, const char *src, size_t size)
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0U && *d != '\0')
while (n-- != 0U && *d != '\0') {
d++;
}
dlen = d - dst;
n = size - dlen;
if (n == 0U)
if (n == 0U) {
return(dlen + strlen(s));
}
while (*s != '\0') {
if (n != 1U) {
*d++ = *s;
@ -290,24 +103,3 @@ isc_string_strlcat(char *dst, const char *src, size_t size)
return(dlen + (s - src)); /* count does not include NUL */
}
char *
isc_string_strcasestr(const char *str, const char *search) {
char c, sc, *s;
size_t len;
if ((c = *search++) != 0) {
c = tolower((unsigned char) c);
len = strlen(search);
do {
do {
if ((sc = *str++) == 0)
return (NULL);
} while ((char) tolower((unsigned char) sc) != c);
} while (strncasecmp(str, search, len) != 0);
str--;
}
DE_CONST(str, s);
return (s);
}

View File

@ -59,6 +59,7 @@ is_ntfs(const char * file) {
char *machinename;
char *sharename;
char filename[1024];
char *last;
REQUIRE(filename != NULL);
@ -78,8 +79,8 @@ is_ntfs(const char * file) {
} else if ((filename[0] == '\\') && (filename[1] == '\\')) {
/* Find the machine and share name and rebuild the UNC */
strlcpy(tmpbuf, filename, sizeof(tmpbuf));
machinename = strtok(tmpbuf, "\\");
sharename = strtok(NULL, "\\");
machinename = strtok_r(tmpbuf, "\\", &last);
sharename = strtok_r(NULL, "\\", &last);
strlcpy(drive, "\\\\", sizeof(drive));
strlcat(drive, machinename, sizeof(drive));
strlcat(drive, "\\", sizeof(drive));

View File

@ -20,6 +20,19 @@
#define ISC_PLATFORM_USETHREADS 1
/*
* Some compatibility cludges
*/
#if defined(_WIN32) || defined(_WIN64)
/* We are on Windows */
# define strtok_r strtok_s
#ifndef strtoull
#define strtoull _strtoui64
#endif
#endif
/***
*** Network.
***/

View File

@ -645,18 +645,8 @@ isc_stdio_sync
isc_stdio_tell
isc_stdio_write
isc_stdtime_get
isc_string_append
isc_string_append_truncate
isc_string_copy
isc_string_copy_truncate
isc_string_printf
isc_string_printf_truncate
isc_string_regiondup
isc_string_separate
isc_string_strcasestr
isc_string_strlcat
isc_string_strlcpy
isc_string_touint64
isc_symtab_count
isc_symtab_create
isc_symtab_define

View File

@ -2552,7 +2552,7 @@ parse_unitstring(char *str, isc_resourcevalue_t *valuep) {
isc_uint64_t value;
isc_uint64_t unit;
value = isc_string_touint64(str, &endp, 10);
value = strtoull(str, &endp, 10);
if (*endp == 0) {
*valuep = value;
return (ISC_R_SUCCESS);
@ -2628,7 +2628,7 @@ parse_sizeval_percent(cfg_parser_t *pctx, const cfg_type_t *type,
goto cleanup;
}
percent = isc_string_touint64(TOKEN_STRING(pctx), &endp, 10);
percent = strtoull(TOKEN_STRING(pctx), &endp, 10);
if (*endp == '%' && *(endp+1) == 0) {
CHECK(cfg_create_obj(pctx, &cfg_type_percentage, &obj));

View File

@ -752,7 +752,7 @@ cfg_parse_percentage(cfg_parser_t *pctx, const cfg_type_t *type,
return (ISC_R_UNEXPECTEDTOKEN);
}
percent = isc_string_touint64(TOKEN_STRING(pctx), &endp, 10);
percent = strtoull(TOKEN_STRING(pctx), &endp, 10);
if (*endp != '%' || *(endp+1) != 0) {
cfg_parser_error(pctx, CFG_LOG_NEAR,
"expected percentage");

View File

@ -467,17 +467,18 @@ set_nextqname(struct probe_trans *trans) {
isc_buffer_t b;
char buf[4096]; /* XXX ad-hoc constant, but should be enough */
if (*trans->qlabel == NULL)
if (*trans->qlabel == NULL) {
return (ISC_R_NOMORE);
}
result = isc_string_copy(buf, sizeof(buf), *trans->qlabel);
if (result != ISC_R_SUCCESS)
return (result);
result = isc_string_append(buf, sizeof(buf), trans->domain);
if (result != ISC_R_SUCCESS)
return (result);
if (strlcpy(buf, *trans->qlabel, sizeof(buf)) >= sizeof(buf)) {
return ISC_R_NOSPACE;
}
domainlen = strlen(buf);
if ((domainlen = strlcat(buf, trans->domain, sizeof(buf))) >= sizeof(buf)) {
return ISC_R_NOSPACE;
}
isc_buffer_init(&b, buf, domainlen);
isc_buffer_add(&b, domainlen);
trans->qname = dns_fixedname_initname(&trans->fixedname);