Code

remote: fix remote set-url usage
[git.git] / http-backend.c
index 7f48406d6dd8a3b67ade9a6b532a8c5764d61504..345c12b79064f23e0ae0a15781731b9a42272d83 100644 (file)
@@ -108,6 +108,7 @@ static const char *get_parameter(const char *name)
        return i ? i->util : NULL;
 }
 
+__attribute__((format (printf, 2, 3)))
 static void format_write(int fd, const char *fmt, ...)
 {
        static char buffer[1024];
@@ -165,6 +166,7 @@ static void end_headers(void)
        safe_write(1, "\r\n", 2);
 }
 
+__attribute__((format (printf, 1, 2)))
 static NORETURN void not_found(const char *err, ...)
 {
        va_list params;
@@ -180,6 +182,7 @@ static NORETURN void not_found(const char *err, ...)
        exit(0);
 }
 
+__attribute__((format (printf, 1, 2)))
 static NORETURN void forbidden(const char *err, ...)
 {
        va_list params;
@@ -615,7 +618,7 @@ int main(int argc, char **argv)
                if (regcomp(&re, c->pattern, REG_EXTENDED))
                        die("Bogus regex in service table: %s", c->pattern);
                if (!regexec(&re, dir, 1, out, 0)) {
-                       size_t n = out[0].rm_eo - out[0].rm_so;
+                       size_t n;
 
                        if (strcmp(method, c->method)) {
                                const char *proto = getenv("SERVER_PROTOCOL");
@@ -629,9 +632,10 @@ int main(int argc, char **argv)
                        }
 
                        cmd = c;
+                       n = out[0].rm_eo - out[0].rm_so;
                        cmd_arg = xmalloc(n);
-                       strncpy(cmd_arg, dir + out[0].rm_so + 1, n);
-                       cmd_arg[n] = '\0';
+                       memcpy(cmd_arg, dir + out[0].rm_so + 1, n-1);
+                       cmd_arg[n-1] = '\0';
                        dir[out[0].rm_so] = 0;
                        break;
                }
@@ -644,6 +648,9 @@ int main(int argc, char **argv)
        setup_path();
        if (!enter_repo(dir, 0))
                not_found("Not a git repository: '%s'", dir);
+       if (!getenv("GIT_HTTP_EXPORT_ALL") &&
+           access("git-daemon-export-ok", F_OK) )
+               not_found("Repository not exported: '%s'", dir);
 
        git_config(http_config, NULL);
        cmd->imp(cmd_arg);