commit 67606321850286a3a613541da555fd6642abaccd from: Stefan Sperling date: Thu Jun 21 19:40:51 2018 UTC fix path length accounting in got_object_open_by_path() commit - db37e2c0e0f236d601b825eb1742db37478a938b commit + 67606321850286a3a613541da555fd6642abaccd blob - 365f923eff07a2a419e8ea238c2fb77c1fe0f65f blob + 530f08f012ebee6cb4dcacf2a20e838ee7f87618 --- lib/object.c +++ lib/object.c @@ -1407,6 +1407,7 @@ got_object_open_by_path(struct got_object **obj, struc struct got_tree_object *tree = NULL; struct got_tree_entry *te = NULL; char *seg, *s, *s0 = NULL; + size_t len = strlen(path); *obj = NULL; @@ -1435,18 +1436,20 @@ got_object_open_by_path(struct got_object **obj, struc err = got_error_from_errno(); goto done; } - err = got_canonpath(path, s0, strlen(s0) + 1); + err = got_canonpath(path, s0, len + 1); if (err) goto done; s = s0; s++; /* skip leading '/' */ + len--; seg = s; - while (*s) { + while (len > 0) { struct got_tree_object *next_tree; if (*s != '/') { s++; + len--; if (*s) continue; } @@ -1460,8 +1463,12 @@ got_object_open_by_path(struct got_object **obj, struc goto done; } + if (len == 0) + break; + seg = s + 1; s++; + len--; if (*s) { err = got_object_open_as_tree(&next_tree, repo, te->id);