diff options
author | Russell Belfer <rb@github.com> | 2012-08-12 09:08:45 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-08-12 09:08:45 -0700 |
commit | fdc637c4e266349b35ac4fb45a4e5aa63c5a78e0 (patch) | |
tree | f10522c2c2d3cdce1d894668187a807219acba25 /src/message.c | |
parent | c9d78bde943213f4c2594d1df175336573678b74 (diff) | |
download | libgit2-fdc637c4e266349b35ac4fb45a4e5aa63c5a78e0.tar.gz |
Check prettify message output buffer after cleanup
This makes the message prettify buffer length check accurate.
Diffstat (limited to 'src/message.c')
-rw-r--r-- | src/message.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/message.c b/src/message.c index a4aadb28f..a5cc26237 100644 --- a/src/message.c +++ b/src/message.c @@ -63,10 +63,7 @@ int git_message_prettify(char *message_out, size_t buffer_size, const char *mess { git_buf buf = GIT_BUF_INIT; - if (strlen(message) + 1 > buffer_size) { /* We have to account for a potentially missing \n */ - giterr_set(GITERR_INVALID, "Buffer too short to hold the cleaned message"); - return -1; - } + assert(message_out && buffer_size); *message_out = '\0'; @@ -75,6 +72,11 @@ int git_message_prettify(char *message_out, size_t buffer_size, const char *mess return -1; } + if (buf.size + 1 > buffer_size) { /* +1 for NUL byte */ + giterr_set(GITERR_INVALID, "Buffer too short to hold the cleaned message"); + return -1; + } + git_buf_copy_cstr(message_out, buffer_size, &buf); git_buf_free(&buf); |