fast-import: use xsnprintf for writing sha1s
authorJeff King <peff@peff.net>
Fri, 24 Mar 2017 17:25:22 +0000 (13:25 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Mar 2017 19:34:07 +0000 (12:34 -0700)
When we have to write a sha1 with a newline, we do so by
copying both into a single buffer, so that we can issue a
single write() call.

We use snprintf but don't bother to check the output, since
we know it will fit. However, we should use xsnprintf() in
such a case so that we're notified if our assumption turns
out to be wrong (and to make it easier to audit for
unchecked snprintf calls).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fast-import.c
index 64fe602f0bb62c4848798d1bdb43a7be9ab5f523..9ae2053a8f822d9222e2c233d4d5ca83a6661972 100644 (file)
@@ -3003,7 +3003,7 @@ static void parse_get_mark(const char *p)
        if (!oe)
                die("Unknown mark: %s", command_buf.buf);
 
-       snprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1));
+       xsnprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1));
        cat_blob_write(output, 41);
 }