From 4b4540bb20fa5e229cced74b0bc6b43f374d8be3 Mon Sep 17 00:00:00 2001 From: cheloha Date: Wed, 25 Jul 2018 15:09:48 +0000 Subject: [PATCH] Free operand copies after parsing. We strdup operands before destructively parsing them to keep w(1) output looking nice and neat, but after parsing we ought to free them. We do need to keep copies for file paths, though, so add additional strdups for operands if and of. While here, use the preferred err(1, NULL) for an allocation failure. Also while here, don't assign `oper' to a copy of itself because it looks strange. "sure." deraadt --- bin/dd/args.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/dd/args.c b/bin/dd/args.c index 6cd6de92e5d..033179d5f90 100644 --- a/bin/dd/args.c +++ b/bin/dd/args.c @@ -1,4 +1,4 @@ -/* $OpenBSD: args.c,v 1.29 2018/01/03 19:12:20 schwarze Exp $ */ +/* $OpenBSD: args.c,v 1.30 2018/07/25 15:09:48 cheloha Exp $ */ /* $NetBSD: args.c,v 1.7 1996/03/01 01:18:58 jtc Exp $ */ /*- @@ -95,9 +95,9 @@ jcl(char **argv) in.dbsz = out.dbsz = 512; - while ((oper = *++argv) != NULL) { - if ((oper = strdup(oper)) == NULL) - errx(1, "out of memory"); + while (*++argv != NULL) { + if ((oper = strdup(*argv)) == NULL) + err(1, NULL); if ((arg = strchr(oper, '=')) == NULL) errx(1, "unknown operand %s", oper); *arg++ = '\0'; @@ -113,6 +113,7 @@ jcl(char **argv) tmp.name); ddflags |= ap->set; ap->f(arg); + free(oper); } /* Final sanity checks. */ @@ -218,8 +219,8 @@ f_ibs(char *arg) static void f_if(char *arg) { - - in.name = arg; + if ((in.name = strdup(arg)) == NULL) + err(1, NULL); } static void @@ -233,8 +234,8 @@ f_obs(char *arg) static void f_of(char *arg) { - - out.name = arg; + if ((out.name = strdup(arg)) == NULL) + err(1, NULL); } static void -- 2.20.1