summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Jodeit <moritz@cvs.openbsd.org>2007-04-02 08:04:53 +0000
committerMoritz Jodeit <moritz@cvs.openbsd.org>2007-04-02 08:04:53 +0000
commit1df025fc6b3d269fad5c5f838ecd9a101e37f080 (patch)
treed31fe9a6daffaa9db7530d07a42d241b866a4df0
parente308f93242ab3516371f98ec34ad545dc613c207 (diff)
The scanf(3) family of functions can return EOF (-1) if an input
failure occurs. So check it, before blindly adding it to some pointer. ok millert@
-rw-r--r--usr.bin/sort/init.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/sort/init.c b/usr.bin/sort/init.c
index 31049abbdcd..1b13dd233d6 100644
--- a/usr.bin/sort/init.c
+++ b/usr.bin/sort/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.9 2006/11/16 00:14:34 ray Exp $ */
+/* $OpenBSD: init.c,v 1.10 2007/04/02 08:04:52 moritz Exp $ */
/*-
* Copyright (c) 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: init.c,v 1.9 2006/11/16 00:14:34 ray Exp $";
+static char rcsid[] = "$OpenBSD: init.c,v 1.10 2007/04/02 08:04:52 moritz Exp $";
#endif
#endif /* not lint */
@@ -115,7 +115,9 @@ setcolumn(char *pos, struct field *cur_fld, int gflag)
int tmp;
col = cur_fld->icol.num ? (&(*cur_fld).tcol) : (&(*cur_fld).icol);
- pos += sscanf(pos, "%d", &(col->num));
+ if (sscanf(pos, "%d", &(col->num)) != 1)
+ errx(2, "missing field number");
+ pos++;
while (isdigit(*pos))
pos++;
if (col->num <= 0 && !(col->num == 0 && col == &(cur_fld->tcol)))
@@ -124,7 +126,9 @@ setcolumn(char *pos, struct field *cur_fld, int gflag)
if (!col->num)
errx(2, "cannot indent end of line");
pos++;
- pos += sscanf(pos, "%d", &(col->indent));
+ if (sscanf(pos, "%d", &(col->indent)) != 1)
+ errx(2, "missing offset");
+ pos++;
while (isdigit(*pos))
pos++;
if (&cur_fld->icol == col)