svn commit: trunk/busybox: include libbb
pgf at busybox.net
pgf at busybox.net
Thu Nov 8 12:00:37 PST 2007
Author: pgf
Date: 2007-11-08 12:00:36 -0800 (Thu, 08 Nov 2007)
New Revision: 20386
Log:
xmalloc_follow_symlinks() -- fix ELOOP issue with absolute paths,
return full path in cases where path doesn't resolve to a link.
change name to better differentiate from xmalloc_readlink().
Modified:
trunk/busybox/include/libbb.h
trunk/busybox/libbb/update_passwd.c
trunk/busybox/libbb/xreadlink.c
Changeset:
Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h 2007-11-08 17:40:23 UTC (rev 20385)
+++ trunk/busybox/include/libbb.h 2007-11-08 20:00:36 UTC (rev 20386)
@@ -260,10 +260,10 @@
/* UNUSED: char *xmalloc_realpath(const char *path); */
char *xmalloc_readlink(const char *path);
-char *xmalloc_readlink_follow(const char *path);
char *xmalloc_readlink_or_warn(const char *path);
char *xrealloc_getcwd_or_warn(char *cwd);
+char *xmalloc_follow_symlinks(const char *path);
//TODO: signal(sid, f) is the same? then why?
extern void sig_catch(int,void (*)(int));
Modified: trunk/busybox/libbb/update_passwd.c
===================================================================
--- trunk/busybox/libbb/update_passwd.c 2007-11-08 17:40:23 UTC (rev 20385)
+++ trunk/busybox/libbb/update_passwd.c 2007-11-08 20:00:36 UTC (rev 20386)
@@ -52,7 +52,7 @@
int cnt = 0;
int ret = -1; /* failure */
- filename = xmalloc_readlink_follow(filename);
+ filename = xmalloc_follow_symlinks(filename);
if (filename == NULL)
return -1;
Modified: trunk/busybox/libbb/xreadlink.c
===================================================================
--- trunk/busybox/libbb/xreadlink.c 2007-11-08 17:40:23 UTC (rev 20385)
+++ trunk/busybox/libbb/xreadlink.c 2007-11-08 20:00:36 UTC (rev 20386)
@@ -33,13 +33,16 @@
}
/*
- * this routine is not the same as realpath(), which canonicalizes
- * the given path completely. this routine only follows trailing
- * symlinks until a real file is reached, and returns its name.
- * intermediate symlinks are not expanded. as above, a malloced
- * char* is returned, which must be freed.
+ * this routine is not the same as realpath(), which
+ * canonicalizes the given path completely. this routine only
+ * follows trailing symlinks until a real file is reached, and
+ * returns its name. if the path ends in a dangling link, or if
+ * the target doesn't exist, the path is returned in any case.
+ * intermediate symlinks in the path are not expanded -- only
+ * those at the tail.
+ * a malloced char* is returned, which must be freed by the caller.
*/
-char *xmalloc_readlink_follow(const char *path)
+char *xmalloc_follow_symlinks(const char *path)
{
char *buf;
char *lpc;
@@ -47,23 +50,27 @@
int bufsize;
int looping = MAXSYMLINKS + 1;
- linkpath = xstrdup(path);
+ buf = xstrdup(path);
goto jump_in;
while (1) {
- if (!--looping) {
- free(linkpath);
- free(buf);
- return NULL;
- }
+
linkpath = xmalloc_readlink(buf);
if (!linkpath) {
- if (errno == EINVAL) /* not a symlink */
+ /* not a symlink, or doesn't exist */
+ if (errno == EINVAL || errno == ENOENT)
return buf;
free(buf);
return NULL;
}
- if (linkpath[0] != '/') {
+
+ if (!--looping) {
+ free(linkpath);
+ free(buf);
+ return NULL;
+ }
+
+ if (*linkpath != '/') {
bufsize += strlen(linkpath);
buf = xrealloc(buf, bufsize);
lpc = bb_get_last_path_component_strip(buf);
@@ -71,8 +78,8 @@
free(linkpath);
} else {
free(buf);
+ buf = linkpath;
jump_in:
- buf = linkpath;
bufsize = strlen(buf) + 1;
}
}
More information about the busybox-cvs
mailing list