From ff858da87b218dac947863d3130b31c94ba655d7 Mon Sep 17 00:00:00 2001 From: jedgar Date: Sat, 20 Jan 2001 01:22:31 +0000 Subject: [PATCH] Check strdup() return values Reviewed by: kris --- usr.sbin/apmd/apmd.c | 3 ++- usr.sbin/apmd/contrib/pccardq.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c index 2ebd557204f4..470bcc6481e8 100644 --- a/usr.sbin/apmd/apmd.c +++ b/usr.sbin/apmd/apmd.c @@ -139,7 +139,8 @@ event_cmd_exec_clone(void *this) newone->evcmd.len = oldone->evcmd.len; newone->evcmd.name = oldone->evcmd.name; newone->evcmd.op = oldone->evcmd.op; - newone->line = strdup(oldone->line); + if ((newone->line = strdup(oldone->line)) == NULL) + err(1, "out of memory"); return (struct event_cmd *) newone; } void diff --git a/usr.sbin/apmd/contrib/pccardq.c b/usr.sbin/apmd/contrib/pccardq.c index 20b789d7d273..2bace2298094 100644 --- a/usr.sbin/apmd/contrib/pccardq.c +++ b/usr.sbin/apmd/contrib/pccardq.c @@ -194,9 +194,18 @@ get_slot_info(int so, int slot, char **manuf, char **version, char if (s != NULL && strchr(s, '~') != NULL) goto parse_err; - *manuf = strdup(_manuf); - *version = strdup(_version); - *device = strdup(_device); + if ((*manuf = strdup(_manuf)) == NULL) { + warn("strdup"); + goto err; + } + if ((*version = strdup(_version)) == NULL) { + warn("strdup"); + goto err; + } + if ((*device = strdup(_device)) == NULL) { + warn("strdup"); + goto err; + } if (*manuf == NULL || *version == NULL || *device == NULL) { warn("strdup"); goto err;