return i ? i->util : NULL;
}
+__attribute__((format (printf, 2, 3)))
static void format_write(int fd, const char *fmt, ...)
{
static char buffer[1024];
format_write(1, "%s: %s\r\n", name, value);
}
-static void hdr_int(const char *name, size_t value)
+static void hdr_int(const char *name, uintmax_t value)
{
format_write(1, "%s: %" PRIuMAX "\r\n", name, value);
}
safe_write(1, "\r\n", 2);
}
+__attribute__((format (printf, 1, 2)))
static NORETURN void not_found(const char *err, ...)
{
va_list params;
exit(0);
}
+__attribute__((format (printf, 1, 2)))
static NORETURN void forbidden(const char *err, ...)
{
va_list params;
safe_write(1, buf->buf, buf->len);
}
-static void send_file(const char *the_type, const char *name)
+static void send_local_file(const char *the_type, const char *name)
{
const char *p = git_path("%s", name);
size_t buf_alloc = 8192;
char *buf = xmalloc(buf_alloc);
int fd;
struct stat sb;
- size_t size;
fd = open(p, O_RDONLY);
if (fd < 0)
if (fstat(fd, &sb) < 0)
die_errno("Cannot stat '%s'", p);
- size = xsize_t(sb.st_size);
-
- hdr_int(content_length, size);
+ hdr_int(content_length, sb.st_size);
hdr_str(content_type, the_type);
hdr_date(last_modified, sb.st_mtime);
end_headers();
- while (size) {
+ for (;;) {
ssize_t n = xread(fd, buf, buf_alloc);
if (n < 0)
die_errno("Cannot read '%s'", p);
{
select_getanyfile();
hdr_nocache();
- send_file("text/plain", name);
+ send_local_file("text/plain", name);
}
static void get_loose_object(char *name)
{
select_getanyfile();
hdr_cache_forever();
- send_file("application/x-git-loose-object", name);
+ send_local_file("application/x-git-loose-object", name);
}
static void get_pack_file(char *name)
{
select_getanyfile();
hdr_cache_forever();
- send_file("application/x-git-packed-objects", name);
+ send_local_file("application/x-git-packed-objects", name);
}
static void get_idx_file(char *name)
{
select_getanyfile();
hdr_cache_forever();
- send_file("application/x-git-packed-objects-toc", name);
+ send_local_file("application/x-git-packed-objects-toc", name);
}
static int http_config(const char *var, const char *value, void *cb)
if (root && *root) {
if (!pathinfo || !*pathinfo)
die("GIT_PROJECT_ROOT is set but PATH_INFO is not");
+ if (daemon_avoid_alias(pathinfo))
+ die("'%s': aliased", pathinfo);
strbuf_addstr(&buf, root);
+ if (buf.buf[buf.len - 1] != '/')
+ strbuf_addch(&buf, '/');
+ if (pathinfo[0] == '/')
+ pathinfo++;
strbuf_addstr(&buf, pathinfo);
return strbuf_detach(&buf, NULL);
} else if (path && *path) {
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");
}
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;
}