Skip to content

Commit aa22ef8

Browse files
committed
Merge branch 'jk/daemon-path-ok-check-truncation' into maint
"git daemon" used fixed-length buffers to turn URL to the repository the client asked for into the server side directory path, using snprintf() to avoid overflowing these buffers, but allowed possibly truncated paths to the directory. This has been tightened to reject such a request that causes overlong path to be required to serve. * jk/daemon-path-ok-check-truncation: daemon: detect and reject too-long paths
2 parents f2ad912 + 6bdb008 commit aa22ef8

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

daemon.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
160160
{
161161
static char rpath[PATH_MAX];
162162
static char interp_path[PATH_MAX];
163+
size_t rlen;
163164
const char *path;
164165
const char *dir;
165166

@@ -187,8 +188,12 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
187188
namlen = slash - dir;
188189
restlen -= namlen;
189190
loginfo("userpath <%s>, request <%s>, namlen %d, restlen %d, slash <%s>", user_path, dir, namlen, restlen, slash);
190-
snprintf(rpath, PATH_MAX, "%.*s/%s%.*s",
191-
namlen, dir, user_path, restlen, slash);
191+
rlen = snprintf(rpath, sizeof(rpath), "%.*s/%s%.*s",
192+
namlen, dir, user_path, restlen, slash);
193+
if (rlen >= sizeof(rpath)) {
194+
logerror("user-path too large: %s", rpath);
195+
return NULL;
196+
}
192197
dir = rpath;
193198
}
194199
}
@@ -207,7 +212,15 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
207212

208213
strbuf_expand(&expanded_path, interpolated_path,
209214
expand_path, &context);
210-
strlcpy(interp_path, expanded_path.buf, PATH_MAX);
215+
216+
rlen = strlcpy(interp_path, expanded_path.buf,
217+
sizeof(interp_path));
218+
if (rlen >= sizeof(interp_path)) {
219+
logerror("interpolated path too large: %s",
220+
interp_path);
221+
return NULL;
222+
}
223+
211224
strbuf_release(&expanded_path);
212225
loginfo("Interpolated dir '%s'", interp_path);
213226

@@ -219,7 +232,11 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
219232
logerror("'%s': Non-absolute path denied (base-path active)", dir);
220233
return NULL;
221234
}
222-
snprintf(rpath, PATH_MAX, "%s%s", base_path, dir);
235+
rlen = snprintf(rpath, sizeof(rpath), "%s%s", base_path, dir);
236+
if (rlen >= sizeof(rpath)) {
237+
logerror("base-path too large: %s", rpath);
238+
return NULL;
239+
}
223240
dir = rpath;
224241
}
225242

0 commit comments

Comments
 (0)