Module Name: src
Committed By: riastradh
Date: Wed Jun 16 23:22:08 UTC 2021
Modified Files:
src/sbin/cgdconfig: cgdconfig.c
Log Message:
cgdconfig(8): Fail more gracefully than SIGSEGV if shell_cmd fails.
To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sbin/cgdconfig/cgdconfig.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/cgdconfig/cgdconfig.c
diff -u src/sbin/cgdconfig/cgdconfig.c:1.51 src/sbin/cgdconfig/cgdconfig.c:1.52
--- src/sbin/cgdconfig/cgdconfig.c:1.51 Sun Apr 18 19:56:09 2021
+++ src/sbin/cgdconfig/cgdconfig.c Wed Jun 16 23:22:08 2021
@@ -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 @@ getkey_shell_cmd(const char *target, str
{
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;
}