Skip to content

Commit

Permalink
upload-archive: convert sprintf to strbuf
Browse files Browse the repository at this point in the history
When we report an error to the client, we format it into a
fixed-size buffer using vsprintf(). This can't actually
overflow in practice, since we only format a very tame
subset of strings (mostly strerror() output). However, it's
hard to tell immediately, so let's just use a strbuf so
readers do not have to wonder.

We do add an allocation here, but the performance is not
important; the next step is to call die() anyway.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Sep 25, 2015
1 parent 495127d commit 0cb9d6d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions builtin/upload-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
__attribute__((format (printf, 1, 2)))
static void error_clnt(const char *fmt, ...)
{
char buf[1024];
struct strbuf buf = STRBUF_INIT;
va_list params;
int len;

va_start(params, fmt);
len = vsprintf(buf, fmt, params);
strbuf_vaddf(&buf, fmt, params);
va_end(params);
send_sideband(1, 3, buf, len, LARGE_PACKET_MAX);
die("sent error to the client: %s", buf);
send_sideband(1, 3, buf.buf, buf.len, LARGE_PACKET_MAX);
die("sent error to the client: %s", buf.buf);
}

static ssize_t process_input(int child_fd, int band)
Expand Down

0 comments on commit 0cb9d6d

Please sign in to comment.