Re: [PATCH 07/12] term-utils: avoid error message string length couting errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, May 11, 2014 at 08:26:44PM +0100, Sami Kerola wrote:
> diff --git a/term-utils/ttymsg.c b/term-utils/ttymsg.c
> index fb2614f..3a2565d 100644
> --- a/term-utils/ttymsg.c
> +++ b/term-utils/ttymsg.c
> @@ -58,6 +58,8 @@
>  #include "pathnames.h"
>  #include "ttymsg.h"
>  
> +enum { ERR_BUFLEN = MAXNAMLEN + 1024 };

 Please, don't use enum in this way, just

    #define ERR_BUFLEN  ...

>  	if (strlen(line) + sizeof(_PATH_DEV) + 1 > sizeof(device)) {
>  		sprintf(errbuf, _("excessively long line arg"));
> -		return (errbuf);
> +		return errbuf;
>  	}

 I have fixed the code to use snprintf() everywhere and to check
 snprintf() return code, that's better than the crazy strlen()+...
 check. 
 
 libc is smart enough to help us.

> +		errbuf[ERR_BUFLEN] = 0;

 Are you sure? :-)

 Fixed and merged.

    Karel


-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux