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 <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 23, 2013 at 01:23 UTC 785a04298177e155dc7391e7234945b38b624e34
2 files changed +3 -10
archive-tar.c
+1 -9
@@ -327,20 +327,12 @@ static struct archiver *find_tar_filter(const char *name, int len)
327 static int tar_filter_config(const char *var, const char *value, void *data)
328 {
329 struct archiver *ar;
330 - const char *dot;
330 const char *name;
331 const char *type;
332 int namelen;
333
335 - if (prefixcmp(var, "tar."))
334 + if (parse_config_key(var, "tar", &name, &namelen, &type) < 0 || !name)
335 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;
336
337 ar = find_tar_filter(name, namelen);
338 if (!ar) {
t/t5000-tar-tree.sh
+2 -1
@@ -212,7 +212,8 @@ test_expect_success 'git-archive --prefix=olde-' '
212 test_expect_success 'setup tar filters' '
213 git config tar.tar.foo.command "tr ab ba" &&
214 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
217 '
218
219 test_expect_success 'archive --list mentions user filter' '