From: Karel Zak Date: Fri, 9 Feb 2007 16:15:39 +0000 (+0100) Subject: swapon: does not correctly deal with symlinks X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=167eaed7836b456b7bedf38be4124a8fa27ccb69;p=util-linux swapon: does not correctly deal with symlinks From: Marco d'Itri Signed-off-by: Karel Zak --- diff --git a/mount/Makefile.am b/mount/Makefile.am index 951fd405..605c4520 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -32,7 +32,7 @@ umount_LDADD = $(top_srcdir)/lib/libenv.a swapon_SOURCES = swapon.c xmalloc.c \ get_label_uuid.c mount_by_label.c mount_blkid.c \ - swap_constants.h + swap_constants.h realpath.c losetup_SOURCES = lomount.c loop.h lomount.h losetup_CFLAGS = -DMAIN diff --git a/mount/swapon.c b/mount/swapon.c index 524547a9..ef8dcee9 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -17,6 +17,12 @@ #include "nls.h" #include "mount_blkid.h" #include "mount_by_label.h" +#include "realpath.h" + +#include /* for PATH_MAX */ +#ifndef PATH_MAX +#define PATH_MAX 8192 +#endif #define streq(s, t) (strcmp ((s), (t)) == 0) @@ -136,9 +142,17 @@ read_proc_swaps(void) { static int is_in_proc_swaps(const char *fname) { int i; + char canonical[PATH_MAX + 2]; + + if (!myrealpath(fname, canonical, PATH_MAX + 1)) { + fprintf(stderr, _("%s: cannot canonicalize %s: %s\n"), + progname, fname, strerror(errno)); + strncpy(canonical, fname, PATH_MAX + 1); + *(canonical + (PATH_MAX + 1)) = '\0'; + } for (i = 0; i < numSwaps; i++) - if (swapFiles[i] && !strcmp(fname, swapFiles[i])) + if (swapFiles[i] && !strcmp(canonical, swapFiles[i])) return 1; return 0; }