Re: [PATCH 10/10] wrapper.c: convert trivial snprintf calls to xsnprintf
- From
Jeff King <peff@peff.net>
- Date
- Jun 3, 2016, 09:13 UTC
- Message-ID
- <20160603091347.GG28401@sigill.intra.peff.net>
- In-Reply-To
- <20160603074724.12173-10-gitter.spiros@gmail.com>
On Fri, Jun 03, 2016 at 07:47:24AM +0000, Elia Pinto wrote:
Show 21 quoted lines
> diff --git a/wrapper.c b/wrapper.c
> index 5dc4e15..0d44835 100644
> --- a/wrapper.c
> +++ b/wrapper.c
> @@ -433,16 +433,11 @@ int xmkstemp(char *template)
> int git_mkstemp(char *path, size_t len, const char *template)
> {
> const char *tmp;
> - size_t n;
>
> tmp = getenv("TMPDIR");
> if (!tmp)
> tmp = "/tmp";
> - n = snprintf(path, len, "%s/%s", tmp, template);
> - if (len <= n) {
> - errno = ENAMETOOLONG;
> - return -1;
> - }
> + (void)xsnprintf(path, len, "%s/%s", tmp, template);
> return mkstemp(path);
> }I don't think this one is a good change. git_mkstemp is a library function, and there are places that indirectly call it (via the gpg code) that do not die when it fails (and even if all the callers _did_ die, isn't "could not create temporary file ..." a better error message than "BUG: attempt to snprintf into too-small buffer"?).
-Peff