]> Kevux Git Server - rit/commitdiff
archive-tar: use parse_config_key when parsing config
authorJeff King <peff@peff.net>
Wed, 23 Jan 2013 06:23:27 +0000 (01:23 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Jan 2013 16:41:50 +0000 (08:41 -0800)
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>
archive-tar.c
t/t5000-tar-tree.sh

index d1cce46..719b629 100644 (file)
@@ -327,20 +327,12 @@ static struct archiver *find_tar_filter(const char *name, int len)
 static int tar_filter_config(const char *var, const char *value, void *data)
 {
        struct archiver *ar;
-       const char *dot;
        const char *name;
        const char *type;
        int namelen;
 
-       if (prefixcmp(var, "tar."))
+       if (parse_config_key(var, "tar", &name, &namelen, &type) < 0 || !name)
                return 0;
-       dot = strrchr(var, '.');
-       if (dot == var + 9)
-               return 0;
-
-       name = var + 4;
-       namelen = dot - name;
-       type = dot + 1;
 
        ar = find_tar_filter(name, namelen);
        if (!ar) {
index e7c240f..3fbd366 100755 (executable)
@@ -212,7 +212,8 @@ test_expect_success 'git-archive --prefix=olde-' '
 test_expect_success 'setup tar filters' '
        git config tar.tar.foo.command "tr ab ba" &&
        git config tar.bar.command "tr ab ba" &&
-       git config tar.bar.remote true
+       git config tar.bar.remote true &&
+       git config tar.invalid baz
 '
 
 test_expect_success 'archive --list mentions user filter' '