Skip to content
This repository was archived by the owner on Jul 2, 2019. It is now read-only.

Commit 785a042

Browse files
peffgitster
authored andcommitted
archive-tar: use parse_config_key when parsing config
This is fewer lines of code, but more importantly, fixes a bogus pointer offset. We are looking for "tar." in the section, but later assume that the dot we found is at offset 9, not 3. This is a holdover from an earlier iteration of 767cf45 which called the section "tarfilter". As a result, we could erroneously reject some filters with dots in their name, as well as read uninitialized memory. Reported by (and test by) René Scharfe. Signed-off-by: Jeff King <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b86bbb commit 785a042

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

archive-tar.c

+1-9
Original file line numberDiff line numberDiff line change
@@ -327,20 +327,12 @@ static struct archiver *find_tar_filter(const char *name, int len)
327327
static int tar_filter_config(const char *var, const char *value, void *data)
328328
{
329329
struct archiver *ar;
330-
const char *dot;
331330
const char *name;
332331
const char *type;
333332
int namelen;
334333

335-
if (prefixcmp(var, "tar."))
334+
if (parse_config_key(var, "tar", &name, &namelen, &type) < 0 || !name)
336335
return 0;
337-
dot = strrchr(var, '.');
338-
if (dot == var + 9)
339-
return 0;
340-
341-
name = var + 4;
342-
namelen = dot - name;
343-
type = dot + 1;
344336

345337
ar = find_tar_filter(name, namelen);
346338
if (!ar) {

t/t5000-tar-tree.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ test_expect_success 'git-archive --prefix=olde-' '
212212
test_expect_success 'setup tar filters' '
213213
git config tar.tar.foo.command "tr ab ba" &&
214214
git config tar.bar.command "tr ab ba" &&
215-
git config tar.bar.remote true
215+
git config tar.bar.remote true &&
216+
git config tar.invalid baz
216217
'
217218

218219
test_expect_success 'archive --list mentions user filter' '

0 commit comments

Comments
 (0)