We already have these checks in many printf-type functions that have
prototypes which are in header files. Add these same checks to
static functions in http-backend.c
Signed-off-by: Tarmigan Casebolt <redacted>
---
Shawn, please consider this patch in addition to the one that you posted
that actually fixes the bug. With this patch, gcc will warn about that bug.
http-backend.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
@@ -626,7 +626,7 @@ int main(int argc, char **argv)}cmd=c;-cmd_arg=xmalloc(n);+cmd_arg=xmalloc(n+1);strncpy(cmd_arg,dir+out[0].rm_so+1,n);cmd_arg[n]='\0';dir[out[0].rm_so]=0;
The cmd_arg string was simply allocated too small. Your fix is
terminating the string one character too short which would cause
get_loose_object and get_pack_file to break.
--
Shawn.
From: Shawn O. Pearce <hidden> Date: 2016-06-15 22:47:43
Tarmigan Casebolt [off-list ref] wrote:
We already have these checks in many printf-type functions that have
prototypes which are in header files. Add these same checks to
static functions in http-backend.c
Signed-off-by: Tarmigan Casebolt <redacted>
---
Shawn, please consider this patch in addition to the one that you posted
that actually fixes the bug. With this patch, gcc will warn about that bug.
Yup, it would have caught it, thanks.
Acked-by: Shawn O. Pearce <redacted>
--
Shawn.
@@ -626,7 +626,7 @@ int main(int argc, char **argv)}cmd=c;-cmd_arg=xmalloc(n);+cmd_arg=xmalloc(n+1);strncpy(cmd_arg,dir+out[0].rm_so+1,n);cmd_arg[n]='\0';dir[out[0].rm_so]=0;
The cmd_arg string was simply allocated too small. Your fix is
terminating the string one character too short which would cause
get_loose_object and get_pack_file to break.
Actually, from my reading, I think his fix is right, because you trim
the first character during the strncpy (using "out[0].rm_so + 1"). But
it's not clear when you create 'n' that you are dropping that character.
IOW, you are doing:
/* string + '\0' - '/' */
size_t n = out[0].rm_eo - (out[0].rm_so + 1) + 1;
which ends up the same as your n, but means that the NUL goes at
cmd_arg[n-1]. But I didn't actually run it, so if his fix is breaking
things, then both Tarmigan and I are counting wrong. ;)
-Peff