summaryrefslogtreecommitdiffstats
path: root/mount/realpath.c
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:43 +0100
committerKarel Zak2006-12-07 00:25:43 +0100
commit22853e4a82c6ef7b336527529acb94b14a0b0fd8 (patch)
treeee28e4598c8c449d7e811711d8ce8eb17caecfb6 /mount/realpath.c
parentImported from util-linux-2.10f tarball. (diff)
downloadkernel-qcow2-util-linux-22853e4a82c6ef7b336527529acb94b14a0b0fd8.tar.gz
kernel-qcow2-util-linux-22853e4a82c6ef7b336527529acb94b14a0b0fd8.tar.xz
kernel-qcow2-util-linux-22853e4a82c6ef7b336527529acb94b14a0b0fd8.zip
Imported from util-linux-2.10m tarball.
Diffstat (limited to 'mount/realpath.c')
-rw-r--r--mount/realpath.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/mount/realpath.c b/mount/realpath.c
index f0d7c76c0..374f8a3a2 100644
--- a/mount/realpath.c
+++ b/mount/realpath.c
@@ -27,18 +27,20 @@
#define MAX_READLINKS 32
+/* this leaks some memory - unimportant for mount */
char *
myrealpath(const char *path, char *resolved_path, int maxreslth) {
- char *npath;
+ char *npath, *buf;
char link_path[PATH_MAX+1];
int readlinks = 0;
- int n;
+ int m, n;
npath = resolved_path;
/* If it's a relative pathname use getcwd for starters. */
if (*path != '/') {
- getcwd(npath, maxreslth-2);
+ if (!getcwd(npath, maxreslth-2))
+ return NULL;
npath += strlen(npath);
if (npath[-1] != '/')
*npath++ = '/';
@@ -100,14 +102,13 @@ myrealpath(const char *path, char *resolved_path, int maxreslth) {
/* Otherwise back up over this component. */
while (*(--npath) != '/')
;
- /* Safe sex check. */
- if (strlen(path) + n >= sizeof(link_path)) {
- errno = ENAMETOOLONG;
- return NULL;
- }
+
/* Insert symlink contents into path. */
- strcat(link_path, path);
- path = xstrdup(link_path);
+ m = strlen(path);
+ buf = xmalloc(m + n + 1);
+ memcpy(buf, link_path, n);
+ memcpy(buf + n, path, m + 1);
+ path = buf;
}
*npath++ = '/';