Skip to content

Commit eecc836

Browse files
Eygene RyabinkinJunio C Hamano
authored andcommitted
Another memory overrun in http-push.c
Use of strlcpy() are wrong, as the source buffer at these locations may not be NUL-terminated.
1 parent 0df56ea commit eecc836

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

http-push.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,9 @@ xml_cdata(void *userData, const XML_Char *s, int len)
12711271
struct xml_ctx *ctx = (struct xml_ctx *)userData;
12721272
free(ctx->cdata);
12731273
ctx->cdata = xmalloc(len + 1);
1274-
strlcpy(ctx->cdata, s, len + 1);
1274+
/* NB: 's' is not null-terminated, can not use strlcpy here */
1275+
memcpy(ctx->cdata, s, len);
1276+
ctx->cdata[len] = '\0';
12751277
}
12761278

12771279
static struct remote_lock *lock_remote(const char *path, long timeout)
@@ -1473,7 +1475,8 @@ static void process_ls_object(struct remote_ls_ctx *ls)
14731475
return;
14741476
path += 8;
14751477
obj_hex = xmalloc(strlen(path));
1476-
strlcpy(obj_hex, path, 3);
1478+
/* NB: path is not null-terminated, can not use strlcpy here */
1479+
memcpy(obj_hex, path, 2);
14771480
strcpy(obj_hex + 2, path + 3);
14781481
one_remote_object(obj_hex);
14791482
free(obj_hex);
@@ -2170,7 +2173,8 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
21702173
/* If it's a symref, set the refname; otherwise try for a sha1 */
21712174
if (!strncmp((char *)buffer.buffer, "ref: ", 5)) {
21722175
*symref = xmalloc(buffer.posn - 5);
2173-
strlcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5);
2176+
memcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 6);
2177+
(*symref)[buffer.posn - 6] = '\0';
21742178
} else {
21752179
get_sha1_hex(buffer.buffer, sha1);
21762180
}

0 commit comments

Comments
 (0)