svn commit: r334070 - head/usr.bin/getconf
Garrett Wollman
wollman at FreeBSD.org
Wed May 23 02:51:58 UTC 2018
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
More information about the svn-src-all
mailing list