From owner-svn-src-all@freebsd.org Wed May 23 02:51:58 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 71A66EEC34A; Wed, 23 May 2018 02:51:58 +0000 (UTC) (envelope-from wollman@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2997173967; Wed, 23 May 2018 02:51:58 +0000 (UTC) (envelope-from wollman@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0AE211CE09; Wed, 23 May 2018 02:51:58 +0000 (UTC) (envelope-from wollman@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4N2pvwR017787; Wed, 23 May 2018 02:51:57 GMT (envelope-from wollman@FreeBSD.org) Received: (from wollman@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4N2pved017260; Wed, 23 May 2018 02:51:57 GMT (envelope-from wollman@FreeBSD.org) Message-Id: <201805230251.w4N2pved017260@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: wollman set sender to wollman@FreeBSD.org using -f From: Garrett Wollman Date: Wed, 23 May 2018 02:51:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334070 - head/usr.bin/getconf X-SVN-Group: head X-SVN-Commit-Author: wollman X-SVN-Commit-Paths: head/usr.bin/getconf X-SVN-Commit-Revision: 334070 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 May 2018 02:51:58 -0000 Author: wollman Date: Wed May 23 02:51:56 2018 New Revision: 334070 URL: https://svnweb.freebsd.org/changeset/base/334070 Log: Move unsigned limits to a separate table/recognizer and display them using the appropriate (unsigned) format specification. This prevents integer overflow when ULLONG_MAX and (on some architectures) ULONG_MAX are used to initialize an intmax_t and then displayed as the signed value -1. (A different approach was suggested in the bug report, which I did not use.) If other limits are defined to be unsigned, they could be moved here. PR: 164049 Reported by: Marcus Reid Modified: head/usr.bin/getconf/Makefile head/usr.bin/getconf/getconf.c head/usr.bin/getconf/getconf.h head/usr.bin/getconf/limits.gperf Modified: head/usr.bin/getconf/Makefile ============================================================================== --- head/usr.bin/getconf/Makefile Wed May 23 01:48:09 2018 (r334069) +++ head/usr.bin/getconf/Makefile Wed May 23 02:51:56 2018 (r334070) @@ -4,11 +4,12 @@ PROG= getconf -SRCS= confstr.c getconf.c limits.c pathconf.c progenv.c sysconf.c +SRCS= confstr.c getconf.c limits.c pathconf.c progenv.c sysconf.c \ + unsigned_limits.c CFLAGS+= -I${.CURDIR} CLEANFILES+= confstr.c limits.c pathconf.c progenv.c sysconf.c \ confstr.names limits.names pathconf.names sysconf.names \ - conflicting.names unique.names + conflicting.names unique.names unsigned_limits.names .SUFFIXES: .gperf .names .PHONY: conflicts Modified: head/usr.bin/getconf/getconf.c ============================================================================== --- head/usr.bin/getconf/getconf.c Wed May 23 01:48:09 2018 (r334069) +++ head/usr.bin/getconf/getconf.c Wed May 23 02:51:56 2018 (r334070) @@ -65,6 +65,7 @@ main(int argc, char **argv) int c, key, valid; const char *name, *vflag, *alt_path; intmax_t limitval; + uintmax_t ulimitval; aflag = false; vflag = NULL; @@ -115,6 +116,13 @@ main(int argc, char **argv) } if (argv[optind + 1] == NULL) { /* confstr or sysconf */ + if ((valid = find_unsigned_limit(name, &ulimitval)) != 0) { + if (valid > 0) + printf("%" PRIuMAX "\n", ulimitval); + else + printf("undefined\n"); + return 0; + } if ((valid = find_limit(name, &limitval)) != 0) { if (valid > 0) printf("%" PRIdMAX "\n", limitval); Modified: head/usr.bin/getconf/getconf.h ============================================================================== --- head/usr.bin/getconf/getconf.h Wed May 23 01:48:09 2018 (r334069) +++ head/usr.bin/getconf/getconf.h Wed May 23 02:51:56 2018 (r334070) @@ -37,6 +37,7 @@ typedef long long intmax_t; #endif int find_confstr(const char *name, int *key); +int find_unsigned_limit(const char *name, uintmax_t *value); int find_limit(const char *name, intmax_t *value); int find_pathconf(const char *name, int *key); int find_progenv(const char *name, const char **alt_path); Modified: head/usr.bin/getconf/limits.gperf ============================================================================== --- head/usr.bin/getconf/limits.gperf Wed May 23 01:48:09 2018 (r334069) +++ head/usr.bin/getconf/limits.gperf Wed May 23 02:51:56 2018 (r334070) @@ -86,11 +86,6 @@ SCHAR_MIN, SCHAR_MIN SHRT_MAX, SHRT_MAX SHRT_MIN, SHRT_MIN SSIZE_MAX, SSIZE_MAX -UCHAR_MAX, UCHAR_MAX -UINT_MAX, UINT_MAX -ULLONG_MAX, ULLONG_MAX -ULONG_MAX, ULONG_MAX -USHRT_MAX, USHRT_MAX WORD_BIT, WORD_BIT CHARCLASS_NAME_MAX, CHARCLASS_NAME_MAX NL_ARGMAX, NL_ARGMAX