Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
resolve_symlink(): use a strbuf for internal scratch space
author
Michael Haggerty
<mhagger@alum.mit.edu>
Wed, 1 Oct 2014 10:28:33 +0000
(12:28 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Wed, 1 Oct 2014 20:51:29 +0000
(13:51 -0700)
Aside from shortening and simplifying the code, this removes another
place where the path name length is arbitrarily limited.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
lockfile.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
cf6950d
)
diff --git
a/lockfile.c
b/lockfile.c
index 85c8648c51ebff7f47da1763e77ad1cddac32a4e..cc9b9cbaf8c7dee11c31509bfd3a435dd3fa2b2c 100644
(file)
--- a/
lockfile.c
+++ b/
lockfile.c
@@
-126,44
+126,35
@@
static char *last_path_elm(char *p)
static char *resolve_symlink(char *p, size_t s)
{
int depth = MAXDEPTH;
static char *resolve_symlink(char *p, size_t s)
{
int depth = MAXDEPTH;
+ static struct strbuf link = STRBUF_INIT;
while (depth--) {
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, strlen(p)) < 0)
+ break;
- if (is_absolute_path(link)) {
+ if (is_absolute_path(link
.buf
)) {
/* absolute path simply replaces p */
/* absolute path simply replaces p */
- if (link
_
len < s)
- strcpy(p, link);
+ if (link
.
len < s)
+ strcpy(p, link
.buf
);
else {
warning("%s: symlink too long", p);
else {
warning("%s: symlink too long", p);
-
return p
;
+
break
;
}
} else {
/*
}
} else {
/*
- * link is a relative path, so
I must
replace the
+ * link is a relative path, so replace the
* last element of p with it.
*/
char *r = (char *)last_path_elm(p);
* last element of p with it.
*/
char *r = (char *)last_path_elm(p);
- if (r - p + link
_
len < s)
- strcpy(r, link);
+ if (r - p + link
.
len < s)
+ strcpy(r, link
.buf
);
else {
warning("%s: symlink too long", p);
else {
warning("%s: symlink too long", p);
-
return p
;
+
break
;
}
}
}
}
}
}
+ strbuf_reset(&link);
return p;
}
return p;
}