Skip to content

Commit 550fbca

Browse files
peffgitster
authored andcommitted
daemon: handle NULs in extended attribute string
If we receive a request with extended attributes after the NUL, we try to write those attributes to the log. We do so with a "%s" format specifier, which will only show characters up to the first NUL. That's enough for printing a "host=" specifier. But since dfe422d (daemon: recognize hidden request arguments, 2017-10-16) we may have another NUL, followed by protocol parameters, and those are not logged at all. Let's cut out the attempt to show the whole string, and instead log when we parse individual attributes. We could leave the "extended attributes (%d bytes) exist" part of the log, which in theory could alert us to attributes that fail to parse. But anything we don't parse as a "host=" parameter gets blindly added to the "protocol" attribute, so we'd see it in that part of the log. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 19136be commit 550fbca

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

daemon.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ static char *parse_host_arg(struct hostinfo *hi, char *extra_args, int buflen)
597597
if (strncasecmp("host=", extra_args, 5) == 0) {
598598
val = extra_args + 5;
599599
vallen = strlen(val) + 1;
600+
loginfo("Extended attribute \"host\": %s", val);
600601
if (*val) {
601602
/* Split <host>:<port> at colon. */
602603
char *host;
@@ -647,9 +648,11 @@ static void parse_extra_args(struct hostinfo *hi, struct argv_array *env,
647648
}
648649
}
649650

650-
if (git_protocol.len > 0)
651+
if (git_protocol.len > 0) {
652+
loginfo("Extended attribute \"protocol\": %s", git_protocol.buf);
651653
argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=%s",
652654
git_protocol.buf);
655+
}
653656
strbuf_release(&git_protocol);
654657
}
655658

@@ -757,10 +760,6 @@ static int execute(void)
757760
alarm(0);
758761

759762
len = strlen(line);
760-
if (pktlen != len)
761-
loginfo("Extended attributes (%d bytes) exist <%.*s>",
762-
(int) pktlen - len - 1,
763-
(int) pktlen - len - 1, line + len + 1);
764763
if (len && line[len-1] == '\n') {
765764
line[--len] = 0;
766765
pktlen--;

t/t5570-git-daemon.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ test_expect_success 'hostname cannot break out of directory' '
183183
git ls-remote "$GIT_DAEMON_URL/escape.git"
184184
'
185185

186-
test_expect_success 'daemon log records hostnames' '
186+
test_expect_success 'daemon log records all attributes' '
187187
cat >expect <<-\EOF &&
188-
Extended attributes (15 bytes) exist <host=localhost>
188+
Extended attribute "host": localhost
189+
Extended attribute "protocol": version=1
189190
EOF
190191
>daemon.log &&
191192
GIT_OVERRIDE_VIRTUAL_HOST=localhost \
192-
git ls-remote "$GIT_DAEMON_URL/interp.git" &&
193+
git -c protocol.version=1 \
194+
ls-remote "$GIT_DAEMON_URL/interp.git" &&
193195
grep -i extended.attribute daemon.log | cut -d" " -f2- >actual &&
194196
test_cmp expect actual
195197
'

0 commit comments

Comments
 (0)