]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fast-import: forbid escaped NUL in paths
authorThalia Archibald <thalia@archibald.dev>
Sun, 14 Apr 2024 01:12:19 +0000 (01:12 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2024 17:06:18 +0000 (10:06 -0700)
NUL cannot appear in paths. Even disregarding filesystem path
limitations, the tree object format delimits with NUL, so such a path
cannot be encoded by Git.

When a quoted path is unquoted, it could possibly contain NUL from
"\000". Forbid it so it isn't truncated.

fast-import still has other issues with NUL, but those will be addressed
later.

Signed-off-by: Thalia Archibald <thalia@archibald.dev>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-fast-import.txt
builtin/fast-import.c
t/t9300-fast-import.sh

index c6082c3b49715972c17be4f8a84692a58150e462..8b6dde45f18e621116354baed6b0130ab9960b2c 100644 (file)
@@ -661,6 +661,7 @@ and its value must be in canonical form. That is it must not:
 
 The root of the tree can be represented by an empty string as `<path>`.
 
+`<path>` cannot contain NUL, either literally or escaped as `\000`.
 It is recommended that `<path>` always be encoded using UTF-8.
 
 `filedelete`
index 832d0055f9c9098e9ddbf638f7e780516a0b4a7f..419ffdcdb5c3a843d0ee037eb046208998b80494 100644 (file)
@@ -2270,6 +2270,8 @@ static void parse_path(struct strbuf *sb, const char *p, const char **endp,
        if (*p == '"') {
                if (unquote_c_style(sb, p, endp))
                        die("Invalid %s: %s", field, command_buf.buf);
+               if (strlen(sb->buf) != sb->len)
+                       die("NUL in %s: %s", field, command_buf.buf);
        } else {
                /*
                 * Unless we are parsing the last field of a line,
index 5cde8f8d01c27bbb34073873494e35a0b98b0274..1e68426852f92c2fe4a7bb4eeea199e910df04dd 100755 (executable)
@@ -3300,6 +3300,7 @@ test_path_base_fail () {
        local change="$1" prefix="$2" field="$3" suffix="$4"
        test_path_fail "$change" 'unclosed " in '"$field"          "$prefix" '"hello.c'    "$suffix" "Invalid $field"
        test_path_fail "$change" "invalid escape in quoted $field" "$prefix" '"hello\xff"' "$suffix" "Invalid $field"
+       test_path_fail "$change" "escaped NUL in quoted $field"    "$prefix" '"hello\000"' "$suffix" "NUL in $field"
 }
 test_path_eol_quoted_fail () {
        local change="$1" prefix="$2" field="$3"