From c726c7f2258cf05ee71bb1784d1b4d2a35193c4b Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 4 Dec 2006 15:05:20 +0000 Subject: check confstr() return value. Due to the braindead return value specified by POSIX we have to clear errno before; also check for -1 to remain compatible. ok millert@ --- usr.bin/getconf/getconf.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/getconf/getconf.c b/usr.bin/getconf/getconf.c index 89925911875..f889545e2a0 100644 --- a/usr.bin/getconf/getconf.c +++ b/usr.bin/getconf/getconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getconf.c,v 1.9 2003/07/10 00:06:51 david Exp $ */ +/* $OpenBSD: getconf.c,v 1.10 2006/12/04 15:05:19 otto Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: getconf.c,v 1.9 2003/07/10 00:06:51 david Exp $"; +static char rcsid[] = "$OpenBSD: getconf.c,v 1.10 2006/12/04 15:05:19 otto Exp $"; #endif /* not lint */ #include @@ -188,8 +188,15 @@ main(int argc, char *argv[]) break; case CONFSTR: + errno = 0; slen = confstr (cp->value, (char *) 0, (size_t) 0); - + + if (slen == 0 || slen == (size_t)-1) { + if (errno) + err(1, "%s", cp->value); + else + errx(1, "%s", cp->value); + } if ((sval = malloc(slen)) == NULL) err(1, NULL); -- cgit v1.2.3