Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/cgdconfig cgdconfig(8): Fail more gracefully than SIGSE...



details:   https://anonhg.NetBSD.org/src/rev/786681135e3b
branches:  trunk
changeset: 1021770:786681135e3b
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jun 16 23:22:08 2021 +0000

description:
cgdconfig(8): Fail more gracefully than SIGSEGV if shell_cmd fails.

diffstat:

 sbin/cgdconfig/cgdconfig.c |  14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diffs (36 lines):

diff -r 531283bbb75f -r 786681135e3b sbin/cgdconfig/cgdconfig.c
--- a/sbin/cgdconfig/cgdconfig.c        Wed Jun 16 21:53:51 2021 +0000
+++ b/sbin/cgdconfig/cgdconfig.c        Wed Jun 16 23:22:08 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.c,v 1.51 2021/04/18 19:56:09 maya Exp $ */
+/* $NetBSD: cgdconfig.c,v 1.52 2021/06/16 23:22:08 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 2002, 2003\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: cgdconfig.c,v 1.51 2021/04/18 19:56:09 maya Exp $");
+__RCSID("$NetBSD: cgdconfig.c,v 1.52 2021/06/16 23:22:08 riastradh Exp $");
 #endif
 
 #include <err.h>
@@ -460,10 +460,14 @@
 {
        FILE    *f;
        bits_t  *ret;
+       int     status;
 
-       f = popen(string_tocharstar(kg->kg_cmd), "r");
-       ret = bits_fget(f, keylen);
-       pclose(f);
+       if ((f = popen(string_tocharstar(kg->kg_cmd), "r")) == NULL)
+               errx(1, "command failed");
+       if ((ret = bits_fget(f, keylen)) == NULL)
+               errx(1, "command output too short");
+       if ((status = pclose(f)) != 0)
+               err(1, "command failed with status %d", status);
 
        return ret;
 }



Home | Main Index | Thread Index | Old Index