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
[-- Attachment #1 --]
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;
: }
: }
: }
[-- Attachment #2 --]
-----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>
