daemon: sanitize all directory separators
PATCH 1/1 daemon: sanitize all directory separators
When sanitizing client-supplied strings on Windows, also strip off backslashes, not just slashes.
--- daemon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
daemon.c +4 -4
@@ -566,14 +566,14 @@ static void parse_host_and_port(char *hostport, char **host,/* * Sanitize a string from the client so that it's OK to be inserted into a -* filesystem path. Specifically, we disallow slashes, runs of "..", and -* trailing and leading dots, which means that the client cannot escape -* our base path via ".." traversal. +* filesystem path. Specifically, we disallow directory separators, runs +* of "..", and trailing and leading dots, which means that the client +* cannot escape our base path via ".." traversal. */ static void sanitize_client (struct strbuf *out,const char *in) {for (; *in; in++) { -if (*in =='/' ) +if (is_dir_sep (*in))continue ;if (*in =='.' && (!out->len || out->buf[out->len -1 ] =='.' ))continue ;
--
2.30.2
daemon.c static void parse_host_and_port(char *hostport, char **host, · line 576
Quoted 8 lines · René Scharfe.
When sanitizing client-supplied strings on Windows, also strip off backslashes, not just slashes.
[...]
static voidsanitize_client(struct strbuf *out, const char *in){daemon.c +1
-1for (; *in; in++) { -if (*in =='/' ) +if (is_dir_sep (*in))
Yeah, this seems like the obviously correct thing to be doing.
-Peff
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Junio & René,
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · René Scharfe.
When sanitizing client-supplied strings on Windows, also strip off backslashes, not just slashes.
Quoted 7 lines
Quoted 4 lines
Signed-off-by René Scharfe <[email protected]>--- daemon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)I do not know how common is it to run "git daemon" on Windows, but it would be nice to have at least an ack from Windows person.
Here is my ACK.
I do not have any precise numbers, of course, as we do not have any telemetry in Git for Windows (for better or worse).
There _are_ occasional reports about something in git daemon not working; Most notably, you have to turn off the sideband to make push work.
Quoted 6 lines
Quoted 6 lines
daemon.c +0
-0@@ -566,14 +566,14 @@ static void parse_host_and_port(char *hostport, char **host,
Quoted 12 lines
daemon.c static void parse_host_and_port(char *hostport, char **host, · line 571
Quoted 8 lines
daemon.c +3
-3/* * Sanitize a string from the client so that it's OK to be inserted into a -* filesystem path. Specifically, we disallow slashes, runs of "..", and -* trailing and leading dots, which means that the client cannot escape -* our base path via ".." traversal. +* filesystem path. Specifically, we disallow directory separators, runs +* of "..", and trailing and leading dots, which means that the client +* cannot escape our base path via ".." traversal. Not a new problem, but "runs of '..'" confused me. If I am reading the code right, we disallow directory separators (by ignoring) and two or more '.' in a row (by squashing them into a single '.').
Indeed, the code is a bit funny in that respect. But at least it keeps us somewhat safe: there is currently no way to break out of the directory to the parent directory, whether with this path or not. (Phew!)
Thanks,
Dscho
Quoted 15 lines
Quoted 11 lines
daemon.c +1
-2*/ static void sanitize_client (struct strbuf *out,const char *in) {for (; *in; in++) { -if (*in =='/' ) +if (is_dir_sep (*in))continue ;if (*in =='.' && (!out->len || out->buf[out->len -1 ] =='.' ))continue ; --Quoted 1 line
2.30.2
Thanks.