Mercurial > hg
changeset 30756:1f9684fe94cc
chg: check snprintf result strictly
This makes the program more robust when somebody changes hgclient's
maxdatasize in the future.
author | Jun Wu <quark@fb.com> |
---|---|
date | Wed, 11 Jan 2017 23:39:24 +0800 |
parents | 0fbb3a5c188e |
children | 511a4bf52754 |
files | contrib/chg/hgclient.c |
diffstat | 1 files changed, 4 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/chg/hgclient.c Tue Jan 10 09:32:27 2017 +0100 +++ b/contrib/chg/hgclient.c Wed Jan 11 23:39:24 2017 +0800 @@ -366,9 +366,11 @@ static void updateprocname(hgclient_t *hgc) { - size_t n = (size_t)snprintf(hgc->ctx.data, hgc->ctx.maxdatasize, + int r = snprintf(hgc->ctx.data, hgc->ctx.maxdatasize, "chg[worker/%d]", (int)getpid()); - hgc->ctx.datasize = n; + if (r < 0 || (size_t)r >= hgc->ctx.maxdatasize) + abortmsg("insufficient buffer to write procname (r = %d)", r); + hgc->ctx.datasize = (size_t)r; writeblockrequest(hgc, "setprocname"); }