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

Karel Zak
2014-05-12T12:05:22Z

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@redhat.com>