Re: [PATCH 57/67] receive-pack: simplify keep_arg computation
On Fri, Sep 18, 2015 at 02:43:56PM -0400, Eric Sunshine wrote: > On Tue, Sep 15, 2015 at 12:10 PM, Jeff Kingwrote: > > To generate "--keep=receive-pack $pid on $host", we write > > progressively into a single buffer, which requires keeping > > track of how much we've written so far. But since the result > > is destined to go into our argv array, we can simply use > > argv_array_pushf. > > > > Unfortunately we still have to have a static buffer for the > > s/static/fixed-size/ maybe? Thanks, will change. The term "static buffer overflow" seems stuck in my head (and you can find references via google), even though it does not make sense at all. In C terms, a stack buffer is really an "auto", but I guess "auto buffer overflow" does not have as nice a ring to it. I agree that "fixed-size" is a lot less confusing, and corrected several such cases before sent out the series. I guess I missed one (I'll grep for others). -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 57/67] receive-pack: simplify keep_arg computation
On Tue, Sep 15, 2015 at 12:10 PM, Jeff Kingwrote: > To generate "--keep=receive-pack $pid on $host", we write > progressively into a single buffer, which requires keeping > track of how much we've written so far. But since the result > is destined to go into our argv array, we can simply use > argv_array_pushf. > > Unfortunately we still have to have a static buffer for the s/static/fixed-size/ maybe? > gethostname() call, but at least it now doesn't involve any > extra size computation. And as a bonus, we drop an sprintf > and a strcpy call. > > Signed-off-by: Jeff King > --- > diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c > index 8b50e48..2c82274 100644 > --- a/builtin/receive-pack.c > +++ b/builtin/receive-pack.c > @@ -1524,15 +1524,18 @@ static const char *unpack(int err_fd, struct > shallow_info *si) > if (status) > return "unpack-objects abnormal exit"; > } else { > - int s; > - char keep_arg[256]; > - > - s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", > (uintmax_t) getpid()); > - if (gethostname(keep_arg + s, sizeof(keep_arg) - s)) > - strcpy(keep_arg + s, "localhost"); > + char hostname[256]; > > argv_array_pushl(, "index-pack", > -"--stdin", hdr_arg, keep_arg, NULL); > +"--stdin", hdr_arg, NULL); > + > + if (gethostname(hostname, sizeof(hostname))) > + xsnprintf(hostname, sizeof(hostname), "localhost"); > + argv_array_pushf(, > +"--keep=receive-pack %"PRIuMAX" on %s", > +(uintmax_t)getpid(), > +hostname); > + > if (fsck_objects) > argv_array_pushf(, "--strict%s", > fsck_msg_types.buf); > -- > 2.6.0.rc2.408.ga2926b9 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 57/67] receive-pack: simplify keep_arg computation
To generate "--keep=receive-pack $pid on $host", we write progressively into a single buffer, which requires keeping track of how much we've written so far. But since the result is destined to go into our argv array, we can simply use argv_array_pushf. Unfortunately we still have to have a static buffer for the gethostname() call, but at least it now doesn't involve any extra size computation. And as a bonus, we drop an sprintf and a strcpy call. Signed-off-by: Jeff King--- builtin/receive-pack.c | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 8b50e48..2c82274 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1524,15 +1524,18 @@ static const char *unpack(int err_fd, struct shallow_info *si) if (status) return "unpack-objects abnormal exit"; } else { - int s; - char keep_arg[256]; - - s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid()); - if (gethostname(keep_arg + s, sizeof(keep_arg) - s)) - strcpy(keep_arg + s, "localhost"); + char hostname[256]; argv_array_pushl(, "index-pack", -"--stdin", hdr_arg, keep_arg, NULL); +"--stdin", hdr_arg, NULL); + + if (gethostname(hostname, sizeof(hostname))) + xsnprintf(hostname, sizeof(hostname), "localhost"); + argv_array_pushf(, +"--keep=receive-pack %"PRIuMAX" on %s", +(uintmax_t)getpid(), +hostname); + if (fsck_objects) argv_array_pushf(, "--strict%s", fsck_msg_types.buf); -- 2.6.0.rc2.408.ga2926b9 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html