@@ -1271,7 +1271,9 @@ xml_cdata(void *userData, const XML_Char *s, int len)
1271
1271
struct xml_ctx * ctx = (struct xml_ctx * )userData ;
1272
1272
free (ctx -> cdata );
1273
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' ;
1275
1277
}
1276
1278
1277
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)
1473
1475
return ;
1474
1476
path += 8 ;
1475
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 );
1477
1480
strcpy (obj_hex + 2 , path + 3 );
1478
1481
one_remote_object (obj_hex );
1479
1482
free (obj_hex );
@@ -2170,7 +2173,8 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
2170
2173
/* If it's a symref, set the refname; otherwise try for a sha1 */
2171
2174
if (!strncmp ((char * )buffer .buffer , "ref: " , 5 )) {
2172
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' ;
2174
2178
} else {
2175
2179
get_sha1_hex (buffer .buffer , sha1 );
2176
2180
}
0 commit comments