Date: Mon, 09 Nov 2009 09:19:33 +0200 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Alexander Best <alexbestms@math.uni-muenster.de> Cc: freebsd-hackers@FreeBSD.org, Gabor Kovesdan <gabor@FreeBSD.org> Subject: Re: [patch] burncd: honour for envar SPEED Message-ID: <87y6mg17y2.fsf@kobe.laptop> In-Reply-To: <permail-2009110901223680e26a0b000035b7-a_best01@message-id.uni-muenster.de> (Alexander Best's message of "Mon, 09 Nov 2009 02:22:36 %2B0100 (CET)") References: <permail-2009110901223680e26a0b000035b7-a_best01@message-id.uni-muenster.de>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-=-= On Mon, 09 Nov 2009 02:22:36 +0100 (CET), Alexander Best <alexbestms@math.uni-muenster.de> wrote: > --- burncd.c.typo 2009-11-09 02:19:47.000000000 +0100 > +++ burncd.c 2009-11-09 02:20:27.000000000 +0100 > @@ -85,8 +85,8 @@ > if ((dev = getenv("CDROM")) == NULL) > dev = "/dev/acd0"; > > - if ((env_speed = getenv("WRITE_SPEED")) != NULL) > - if (strcasecmp("max", getenv) == 0) > + if ((env_speed = getenv("WRITE_SPEED")) != NULL) { > + if (strcasecmp("max", env_speed) == 0) > speed = CDR_MAX_SPEED; > else > speed = atoi(env_speed) * 177; atoi() doesn't really have error checking and it does not necessarily affect `errno'. I'd probably prefer something that uses strtoul() and a few more value/range checks, i.e.: : #include <limits.h> : #include <string.h> : : { : char *endp; : long xspeed; : : speed = 4 * 177; : if ((env_speed = getenv("SPEED")) != NULL) { : if (strcasecmp("max", env_speed) == 0) { : speed = CDR_MAX_SPEED; : } else { : end = NULL; : errno = 0; : xspeed = strtol(env_speed, &endp, 0); : if (errno != 0 || (endp != NULL && endp != str && : *endp != '\0' && (isdigit(*endp) != 0 || : isspace(*endp) == 0))) : err(1, "invalid write speed: %s", env_speed); : if (xspeed < 0 || xspeed > INT_MAX) : err(1, "write speed out of range: %ld", xspeed); : speed = (int)xspeed * 177; : } : } : } --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (FreeBSD) iEYEARECAAYFAkr3woUACgkQ1g+UGjGGA7agFQCgqABc/G2c+47gxRnqiK81gcyJ PDMAniHujYEVHvgmUk+0ooepIwI778kT =OfHv -----END PGP SIGNATURE----- --=-=-=--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87y6mg17y2.fsf>