Skip to content

Commit 973d6a2

Browse files
author
Junio C Hamano
committed
update-index --index-info: adjust for funny-path quoting.
Although the sole current user uses -z to read this, we should be prepared for somebody to feed non-z format to the command. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 4d2060e commit 973d6a2

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

update-index.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include "cache.h"
77
#include "strbuf.h"
8+
#include "quote.h"
89

910
/*
1011
* Default to not allowing changes to the list of files. The
@@ -338,6 +339,7 @@ static void read_index_info(int line_termination)
338339
strbuf_init(&buf);
339340
while (1) {
340341
char *ptr;
342+
char *path_name;
341343
unsigned char sha1[20];
342344
unsigned int mode;
343345

@@ -352,14 +354,22 @@ static void read_index_info(int line_termination)
352354
goto bad_line;
353355

354356
ptr += 42;
355-
if (!verify_path(ptr)) {
356-
fprintf(stderr, "Ignoring path %s\n", ptr);
357+
358+
if (line_termination && ptr[0] == '"')
359+
path_name = unquote_c_style(ptr, NULL);
360+
else
361+
path_name = ptr;
362+
363+
if (!verify_path(path_name)) {
364+
fprintf(stderr, "Ignoring path %s\n", path_name);
365+
if (path_name != ptr)
366+
free(path_name);
357367
continue;
358368
}
359369

360370
if (!mode) {
361371
/* mode == 0 means there is no such path -- remove */
362-
if (remove_file_from_cache(ptr))
372+
if (remove_file_from_cache(path_name))
363373
die("git-update-index: unable to remove %s",
364374
ptr);
365375
}
@@ -369,10 +379,12 @@ static void read_index_info(int line_termination)
369379
* ptr[-41] is at the beginning of sha1
370380
*/
371381
ptr[-42] = ptr[-1] = 0;
372-
if (add_cacheinfo(buf.buf, ptr-41, ptr))
382+
if (add_cacheinfo(buf.buf, ptr-41, path_name))
373383
die("git-update-index: unable to update %s",
374-
ptr);
384+
path_name);
375385
}
386+
if (path_name != ptr)
387+
free(path_name);
376388
continue;
377389

378390
bad_line:

0 commit comments

Comments
 (0)