replace trivial malloc + sprintf / strcpy calls with xstrfmt
It's a common pattern to do: foo = xmalloc(strlen(one) + strlen(two) + 1 + 1); sprintf(foo, "%s %s", one, two); (or possibly some variant with strcpy()s or a more complicated length computation). We can switch these to use xstrfmt, which is shorter, involves less error-prone manual computation, and removes many sprintf and strcpy calls which make it harder to audit the code for real buffer overflows. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b7115a350b
commit
75faa45ae0
@ -889,9 +889,8 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)
|
||||
}
|
||||
|
||||
/* response: "<user> <digest in hex>" */
|
||||
resp_len = strlen(user) + 1 + strlen(hex) + 1;
|
||||
response = xmalloc(resp_len);
|
||||
sprintf(response, "%s %s", user, hex);
|
||||
response = xstrfmt("%s %s", user, hex);
|
||||
resp_len = strlen(response) + 1;
|
||||
|
||||
response_64 = xmalloc(ENCODED_SIZE(resp_len) + 1);
|
||||
encoded_len = EVP_EncodeBlock((unsigned char *)response_64,
|
||||
|
Reference in New Issue
Block a user