[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: system/3640: installboot dumps core when given a non numeric argument to -s parameter
- To: bugs@cvs.openbsd.org
- Subject: Re: system/3640: installboot dumps core when given a non numeric argument to -s parameter
- From: Pedro Martelletto <pbastos@rdc.puc-rio.br>
- Date: Tue, 20 Jan 2004 05:25:02 -0700 (MST)
The following reply was made to PR system/3640; it has been noted by GNATS.
From: Pedro Martelletto <pbastos@rdc.puc-rio.br>
To: lsalle@taciturne.net
Cc: gnats@openbsd.org
Subject: Re: system/3640: installboot dumps core when given a non numeric argument to -s parameter
Date: Tue, 20 Jan 2004 10:12:40 -0200
This is happening because an unchecked atoi() is returning 0, a value
that later on the program uses to divide another number by, then causing
the floating point exception. The best way to handle that would be using
one of strtol/strtoul() and checking for {under,over}flows, but anyway,
the attached diff should fix it...
-p.
On Tue, Jan 20, 2004 at 12:10:32PM +0100, lsalle@taciturne.net wrote:
> >Number: 3640
> >Category: system
> >Synopsis: installboot dumps core when given a non numeric argument to -s parameter
> >Confidential: yes
> >Severity: non-critical
> >Priority: low
> >Responsible: bugs
> >State: open
> >Quarter:
> >Keywords:
> >Date-Required:
> >Class: sw-bug
> >Submitter-Id: net
> >Arrival-Date: Tue Jan 20 11:20:02 GMT 2004
> >Closed-Date:
> >Last-Modified:
> >Originator: staff
> >Release: OPENBSD_3_4
> >Organization:
> net
>
> In the following shell script, a non-numeric string follows the -s argument to installboot, resulting in a core dump (floating point exception).
Index: installboot.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/stand/installboot/installboot.c,v
retrieving revision 1.41
diff -u -r1.41 installboot.c
--- installboot.c 2003/08/25 23:27:43 1.41
+++ installboot.c 2004/01/20 12:02:31
@@ -114,10 +114,22 @@
switch (c) {
case 'h':
nheads = atoi(optarg);
+ if (!nheads) {
+ (void)fprintf(stderr,
+ "invalid argument to option -h\n");
+ usage();
+ }
+
userspec = 1;
break;
case 's':
nsectors = atoi(optarg);
+ if (!nsectors) {
+ (void)fprintf(stderr,
+ "invalid argument to option -s\n");
+ usage();
+ }
+
userspec = 1;
break;
case 'n':