@@ -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
12771279static 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