Skip to content


Browse files Browse the repository at this point in the history
daemon: Strictly parse the "extra arg" part of the command
Since (49ba83f "Add virtualization support to git-daemon")
git daemon enters an infinite loop and never terminates if a client
hides any extra arguments in the initial request line which is not
exactly "\0host=blah\0".

Since that change, a client must never insert additional extra
arguments, or attempt to use any argument other than "host=", as
any daemon will get stuck parsing the request line and will never
complete the request.

Since the client can't tell if the daemon is patched or not, it
is not possible to know if additional extra args might actually be
able to be safely requested.

If we ever need to extend the git daemon protocol to support a new
feature, we may have to do something like this to the exchange:

  # If both support git:// v2
  C: 000cgit://v2
  S: 0010ok host user
  C: 0018host
  C: 0027git-upload-pack /pub/linux-2.6.git
  S: ...git-upload-pack header...

  # If client supports git:// v2, server does not:
  C: 000cgit://v2
  S: <EOF>

  C: 003bgit-upload-pack /pub/linux-2.6.git\\0
  S: ...git-upload-pack header...

This requires the client to create two TCP connections to talk to
an older git daemon, however all daemons since the introduction of
daemon.c will safely reject the unknown "git://v2" command request,
so the client can quite easily determine the server supports an
older protocol.

Signed-off-by: Shawn O. Pearce <>
Signed-off-by: Junio C Hamano <>
  • Loading branch information
spearce authored and gitster committed Jun 6, 2009
1 parent 6c7f58d commit 73bb33a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion connect.c
Expand Up @@ -579,7 +579,10 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
git_tcp_connect(fd, host, flags);
* Separate original protocol components prog and path
* from extended components with a NUL byte.
* from extended host header with a NUL byte.
* Note: Do not add any other headers here! Doing so
* will cause older git-daemon servers to crash.
"%s %s%chost=%s%c",
Expand Down
10 changes: 6 additions & 4 deletions daemon.c
Expand Up @@ -406,15 +406,15 @@ static char *xstrdup_tolower(const char *str)

* Separate the "extra args" information as supplied by the client connection.
* Read the host as supplied by the client connection.
static void parse_extra_args(char *extra_args, int buflen)
static void parse_host_arg(char *extra_args, int buflen)
char *val;
int vallen;
char *end = extra_args + buflen;

while (extra_args < end && *extra_args) {
if (extra_args < end && *extra_args) {
saw_extended_args = 1;
if (strncasecmp("host=", extra_args, 5) == 0) {
val = extra_args + 5;
Expand All @@ -436,6 +436,8 @@ static void parse_extra_args(char *extra_args, int buflen)
/* On to the next one */
extra_args = val + vallen;
if (extra_args < end && *extra_args)
die("Invalid request");

Expand Down Expand Up @@ -545,7 +547,7 @@ static int execute(struct sockaddr *addr)
hostname = canon_hostname = ip_address = tcp_port = NULL;

if (len != pktlen)
parse_extra_args(line + len + 1, pktlen - len - 1);
parse_host_arg(line + len + 1, pktlen - len - 1);

for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
struct daemon_service *s = &(daemon_service[i]);
Expand Down

0 comments on commit 73bb33a

Please sign in to comment.