summaryrefslogtreecommitdiff
path: root/usr.sbin/dhcpd
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2010-03-27 14:11:39 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2010-03-27 14:11:39 +0000
commitdc8d6873631e1085f672eef9aec9dc5627ef8b88 (patch)
treef2965665f3048a1ae1dcd752b12ebce837d5e101 /usr.sbin/dhcpd
parent376af098e8410ffd3bc2e136f901114deabe5bde (diff)
malloc/strlcpy -> strdup. Use consistent idiom.
ok (as part of larger diff) blambert@ kettenis@ stsp@ zinovik@
Diffstat (limited to 'usr.sbin/dhcpd')
-rw-r--r--usr.sbin/dhcpd/confpars.c22
-rw-r--r--usr.sbin/dhcpd/memory.c10
-rw-r--r--usr.sbin/dhcpd/parse.c16
-rw-r--r--usr.sbin/dhcpd/sync.c5
4 files changed, 21 insertions, 32 deletions
diff --git a/usr.sbin/dhcpd/confpars.c b/usr.sbin/dhcpd/confpars.c
index f53db1c321b..2851070648c 100644
--- a/usr.sbin/dhcpd/confpars.c
+++ b/usr.sbin/dhcpd/confpars.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: confpars.c,v 1.18 2010/01/02 04:21:16 krw Exp $ */
+/* $OpenBSD: confpars.c,v 1.19 2010/03/27 14:11:38 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
@@ -175,7 +175,7 @@ int parse_statement(cfile, group, type, host_decl, declaration)
int token;
char *val;
struct shared_network *share;
- char *t, *n;
+ char *n;
struct tree *tree;
struct tree_cache *cache;
struct hardware hardware;
@@ -247,11 +247,9 @@ int parse_statement(cfile, group, type, host_decl, declaration)
/* Make the shared network name from network number. */
n = piaddr(share->subnets->net);
- t = malloc(strlen(n) + 1);
- if (!t)
+ share->name = strdup(n);
+ if (share->name == NULL)
error("no memory for subnet name");
- strlcpy(t, n, (strlen(n) + 1));
- share->name = t;
/* Copy the authoritative parameter from the subnet,
since there is no opportunity to declare it here. */
@@ -637,10 +635,9 @@ void parse_shared_net_declaration(cfile, group)
parse_warn("zero-length shared network name");
val = "<no-name-given>";
}
- name = malloc(strlen(val) + 1);
- if (!name)
+ name = strdup(val);
+ if (name == NULL)
error("no memory for shared network name");
- strlcpy(name, val, strlen(val) + 1);
} else {
name = parse_host_name(cfile);
if (!name)
@@ -897,10 +894,9 @@ void parse_option_param(cfile, group)
skip_to_semi(cfile);
return;
}
- vendor = malloc(strlen(val) + 1);
- if (!vendor)
+ vendor = strdup(val);
+ if (vendor == NULL)
error("no memory for vendor token.");
- strlcpy(vendor, val, strlen(val) + 1);
token = peek_token(&val, cfile);
if (token == '.') {
/* Go ahead and take the DOT token... */
@@ -1338,5 +1334,3 @@ parse_address_range(FILE *cfile, struct subnet *subnet)
/* Create the new address range... */
new_address_range(low, high, subnet, dynamic);
}
-
-
diff --git a/usr.sbin/dhcpd/memory.c b/usr.sbin/dhcpd/memory.c
index 31333c99b30..2dd6fcd875d 100644
--- a/usr.sbin/dhcpd/memory.c
+++ b/usr.sbin/dhcpd/memory.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: memory.c,v 1.19 2010/01/01 20:30:25 krw Exp $ */
+/* $OpenBSD: memory.c,v 1.20 2010/03/27 14:11:38 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
@@ -257,14 +257,10 @@ new_address_range(struct iaddr low, struct iaddr high, struct subnet *subnet,
if (!h)
warning("No hostname for %s", inet_ntoa(ia));
else {
- int len = strlen(h->h_name) + 1;
-
- address_range[i].hostname = malloc(len);
- if (!address_range[i].hostname)
+ address_range[i].hostname = strdup(h->h_name);
+ if (address_range[i].hostname == NULL)
error("no memory for hostname %s.",
h->h_name);
- strlcpy(address_range[i].hostname,
- h->h_name, len);
}
}
diff --git a/usr.sbin/dhcpd/parse.c b/usr.sbin/dhcpd/parse.c
index 9e0dc4e2f7e..b7c5159d37b 100644
--- a/usr.sbin/dhcpd/parse.c
+++ b/usr.sbin/dhcpd/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.12 2009/09/01 08:42:31 reyk Exp $ */
+/* $OpenBSD: parse.c,v 1.13 2010/03/27 14:11:38 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -123,10 +123,9 @@ parse_string(FILE *cfile)
skip_to_semi(cfile);
return (NULL);
}
- s = malloc(strlen(val) + 1);
- if (!s)
+ s = strdup(val);
+ if (s == NULL)
error("no memory for string %s.", val);
- strlcpy(s, val, strlen(val) + 1);
if (!parse_semi(cfile)) {
free(s);
@@ -155,9 +154,9 @@ parse_host_name(FILE *cfile)
return (NULL);
}
/* Store this identifier... */
- if (!(s = malloc(strlen(val) + 1)))
+ s = strdup(val);
+ if (s == NULL)
error("can't allocate temp space for hostname.");
- strlcpy(s, val, strlen(val) + 1);
c = cons((caddr_t) s, c);
len += strlen(s) + 1;
/*
@@ -335,10 +334,9 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
convert_num(s, val, base, size);
s += size / 8;
} else {
- t = malloc(strlen(val) + 1);
- if (!t)
+ t = strdup(val);
+ if (t == NULL)
error("no temp space for number.");
- strlcpy(t, val, strlen(val) + 1);
c = cons(t, c);
}
} while (++count != *max);
diff --git a/usr.sbin/dhcpd/sync.c b/usr.sbin/dhcpd/sync.c
index 76cd88887dc..380f631b36b 100644
--- a/usr.sbin/dhcpd/sync.c
+++ b/usr.sbin/dhcpd/sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sync.c,v 1.8 2010/01/03 18:37:06 deraadt Exp $ */
+/* $OpenBSD: sync.c,v 1.9 2010/03/27 14:11:38 krw Exp $ */
/*
* Copyright (c) 2008 Bob Beck <beck@openbsd.org>
@@ -96,7 +96,8 @@ sync_addhost(const char *name, u_short port)
freeaddrinfo(res0);
return (ENOMEM);
}
- if ((shost->h_name = strdup(name)) == NULL) {
+ shost->h_name = strdup(name);
+ if (shost->h_name == NULL) {
free(shost);
freeaddrinfo(res0);
return (ENOMEM);