Re: [PATCH] diesys calls die and also reports strerror(errno)

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

 



On Thu, Jun 04, 2009 at 06:05:05AM +0400, Alexander Potashev wrote:

> Firstly I was going to write a 'adapt_to_fmt' function which would
> double all inclusions of '%', and then use it for strerror(err) and
> make printf-like functions happy (actually 'die_routine').
> 
> BUT, Have you ever seen an error description containing '%'? I haven't.
> So, handling the case of '%'s is not worth injecting several dump lines
> into the sources of the Beatiful Content Tracker.

That makes me a little nervous. No, I don't think there are any '%'
signs in standard 'C' locale messages (at least not in GNU libc). But
what about other locales, especially ones which use a multi-byte
encoding?

Though your code does at least recognize the situation and does
something sane instead of feeding bogus parameters to fprintf.

> +void diesys(const char *err, ...)
> +{
> +	va_list params;
> +	char *fullfmt;
> +	const char *strerr;
> +
> +	va_start(params, err);
> +
> +	strerr = strerror(errno);
> +	if (strchr(strerr, '%'))
> +		strerr = "<error description contains '%%'>";
> +	fullfmt = xmalloc(strlen(err) + strlen(strerr) + 3);
> +	sprintf(fullfmt, "%s: %s", err, strerr);
> +	die_routine(fullfmt, params);
> +
> +	va_end(params);
> +}

Should we be calling malloc here? One of the possible error conditions
is that we're out of memory (though xmalloc itself just uses "die"). I
don't think there is a good reason not to use a reasonably-sized static
buffer, which should increase robustness (report() is already using a
1024-character buffer, so any message would be truncated there anyway).

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]