[patch] burncd: honour for envar SPEED

Giorgos Keramidas keramida at ceid.upatras.gr
Mon Nov 9 07:19:37 UTC 2009


On Mon, 09 Nov 2009 02:22:36 +0100 (CET), Alexander Best <alexbestms at 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;
:                 }
:         }
: }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20091109/d9868a32/attachment.pgp


More information about the freebsd-hackers mailing list