diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2013-04-19 15:51:28 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2013-04-19 15:51:28 +0000 |
commit | b236203f3aefd714b7d79be411976c4a048f5f35 (patch) | |
tree | 5e16a4384764695fc7609270007e46d06d000e5b /usr.bin/find/function.c | |
parent | ae5a359d77d88f7c79441b716ed872f0c48d59f4 (diff) |
handle large numbers. this fixes time_t beyond 2038, constrains the
range of i_num correctly, and now handles files > 4GB in size on 32-bit
machines.
ok otto millert
Diffstat (limited to 'usr.bin/find/function.c')
-rw-r--r-- | usr.bin/find/function.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index b98c7be7430..7dd82b458a1 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $OpenBSD: function.c,v 1.38 2012/01/05 10:21:33 sthen Exp $ */ +/* $OpenBSD: function.c,v 1.39 2013/04/19 15:51:27 deraadt Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -71,7 +71,7 @@ } static PLAN *palloc(enum ntype, int (*)(PLAN *, FTSENT *)); -static long find_parsenum(PLAN *plan, char *option, char *vp, char *endch); +static long long find_parsenum(PLAN *plan, char *option, char *vp, char *endch); static void run_f_exec(PLAN *plan); static PLAN *palloc(enum ntype t, int (*f)(PLAN *, FTSENT *)); @@ -121,10 +121,10 @@ extern FTS *tree; * find_parsenum -- * Parse a string of the form [+-]# and return the value. */ -static long +static long long find_parsenum(PLAN *plan, char *option, char *vp, char *endch) { - long value; + long long value; char *endchar, *str; /* Pointer to character ending conversion. */ /* Determine comparison from leading + or -. */ @@ -148,7 +148,7 @@ find_parsenum(PLAN *plan, char *option, char *vp, char *endch) * and endchar points to the beginning of the string we know we have * a syntax error. */ - value = strtol(str, &endchar, 10); + value = strtoll(str, &endchar, 10); if (value == 0 && endchar == str) errx(1, "%s: %s: illegal numeric value", option, vp); if (endchar[0] && (endch == NULL || endchar[0] != *endch)) @@ -911,12 +911,16 @@ f_inum(PLAN *plan, FTSENT *entry) PLAN * c_inum(char *arg, char ***ignored, int unused) { + long long inum; PLAN *new; ftsoptions &= ~FTS_NOSTAT; new = palloc(N_INUM, f_inum); - new->i_data = find_parsenum(new, "-inum", arg, NULL); + inum = find_parsenum(new, "-inum", arg, NULL); + if (inum != (ino_t)inum) + errx(1, "-inum: %s: number too great", arg); + new->i_data = inum; return (new); } @@ -935,11 +939,15 @@ PLAN * c_links(char *arg, char ***ignored, int unused) { PLAN *new; + long long nlink; ftsoptions &= ~FTS_NOSTAT; new = palloc(N_LINKS, f_links); - new->l_data = (nlink_t)find_parsenum(new, "-links", arg, NULL); + nlink = find_parsenum(new, "-links", arg, NULL); + if (nlink != (nlink_t)nlink) + errx(1, "-links: %s: number too great", arg); + new->l_data = nlink; return (new); } |