diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2014-07-31 20:43:33 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-08-01 09:54:49 -0700 |
commit | bbcf7cf9707525025be03af94f46df34e1aef435 (patch) | |
tree | 88f5974231ff15db5abc6c4335a1e353a7b32d3e | |
parent | 470169a2c42cd7fdf1327fb0009daf99e8a614d1 (diff) | |
download | git-bbcf7cf9707525025be03af94f46df34e1aef435.tar.gz |
lockfile.c: remove PATH_MAX limit in resolve_symlink()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | lockfile.c | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/lockfile.c b/lockfile.c index 968b28f0c0..154915fb1a 100644 --- a/lockfile.c +++ b/lockfile.c @@ -85,52 +85,33 @@ static char *last_path_elm(char *p) static char *resolve_symlink(const char *in) { - static char p[PATH_MAX]; - size_t s = sizeof(p); + static struct strbuf p = STRBUF_INIT; + struct strbuf link = STRBUF_INIT; int depth = MAXDEPTH; - if (strlen(in) >= sizeof(p)) - return NULL; - strcpy(p, in); + strbuf_reset(&p); + strbuf_addstr(&p, in); while (depth--) { - char link[PATH_MAX]; - int link_len = readlink(p, link, sizeof(link)); - if (link_len < 0) { - /* not a symlink anymore */ - return p; - } - else if (link_len < sizeof(link)) - /* readlink() never null-terminates */ - link[link_len] = '\0'; - else { - warning("%s: symlink too long", p); - return p; - } + if (strbuf_readlink(&link, p.buf, 0) < 0) + break; /* not a symlink anymore */ - if (is_absolute_path(link)) { + if (is_absolute_path(link.buf)) { /* absolute path simply replaces p */ - if (link_len < s) - strcpy(p, link); - else { - warning("%s: symlink too long", p); - return p; - } + strbuf_reset(&p); + strbuf_addbuf(&p, &link); } else { /* * link is a relative path, so I must replace the * last element of p with it. */ - char *r = (char *)last_path_elm(p); - if (r - p + link_len < s) - strcpy(r, link); - else { - warning("%s: symlink too long", p); - return p; - } + char *r = (char *)last_path_elm(p.buf); + strbuf_setlen(&p, r - p.buf); + strbuf_addbuf(&p, &link); } } - return p; + strbuf_release(&link); + return p.buf; } |