Another memory overrun in http-push.c
Use of strlcpy() are wrong, as the source buffer at these locations may not be NUL-terminated.
Eygene Ryabinkin committed
Mar 1, 2007 at 19:09 UTC
eecc8367f4eaafc8449fc08c4e33f3f8ac474469
1 file changed
+7
-3
http-push.c
+7
-3
@@ -1271,7 +1271,9 @@ xml_cdata(void *userData, const XML_Char *s, int len)
1271
struct xml_ctx *ctx = (struct xml_ctx *)userData;
1272
free(ctx->cdata);
1273
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';
1277
}
1278
1279
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)
1475
return;
1476
path += 8;
1477
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);
1480
strcpy(obj_hex + 2, path + 3);
1481
one_remote_object(obj_hex);
1482
free(obj_hex);
@@ -2170,7 +2173,8 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
2173
/* If it's a symref, set the refname; otherwise try for a sha1 */
2174
if (!strncmp((char *)buffer.buffer, "ref: ", 5)) {
2175
*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';
2178
} else {
2179
get_sha1_hex(buffer.buffer, sha1);
2180
}