From: Petr Uzel Date: Wed, 26 Jan 2011 11:17:00 +0000 (+0100) Subject: mount: fix parsing offset= followed by more options X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7897c815ba0319146a4fe41f12eaba802dd3b3ff;p=util-linux mount: fix parsing offset= followed by more options mount does not parse parse offset= option if it is followed by other options. In umount, the parsing is done with the get_value() function. This patch moves get_value to fstab.c (with new name get_option_value()) and fixes mount to use the function. [kzak@redhat.com: - rename to get_option_value() - use fstab.c rather than sundries.c] Novell bugzilla: #666150 Reported-by: Ludwig Nussel Signed-off-by: Petr Uzel Signed-off-by: Karel Zak --- diff --git a/mount/fstab.c b/mount/fstab.c index 26d3fc29..069a4084 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -760,6 +760,7 @@ lock_mtab (void) { } } +/* returns whole option with name @optname from @src list */ static char * get_option(const char *optname, const char *src, size_t *len) { @@ -786,6 +787,25 @@ get_option(const char *optname, const char *src, size_t *len) return NULL; } + /* If @list contains "user=peter" and @s is "user=", return "peter" */ +char * +get_option_value(const char *list, const char *s) +{ + const char *t; + size_t n = strlen(s); + + while (list && *list) { + if (strncmp(list, s, n) == 0) { + s = t = list + n; + while (*s && *s != ',') + s++; + return xstrndup(t, s-t); + } + while (*list && *list++ != ',') ; + } + return NULL; +} + static int cpy_option(const char *optname, char *dest, const char *src) { diff --git a/mount/fstab.h b/mount/fstab.h index 850cb67a..f631bebe 100644 --- a/mount/fstab.h +++ b/mount/fstab.h @@ -39,4 +39,6 @@ void lock_mtab (void); void unlock_mtab (void); void update_mtab (const char *special, struct my_mntent *with); +char *get_option_value(const char *list, const char *s); + #endif /* MOUNT_FSTAB_H */ diff --git a/mount/mount.c b/mount/mount.c index bb4bd347..9fd92480 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -2042,16 +2042,17 @@ is_fstab_entry_mounted(struct mntentchn *mc, int verbose) if ((strstr(mc->m.mnt_opts, "loop=") || (stat(mc->m.mnt_fsname, &st) == 0 && S_ISREG(st.st_mode)))) { - char *p = strstr(mc->m.mnt_opts, "offset="); + char *p = get_option_value(mc->m.mnt_opts, "offset="); uintmax_t offset = 0; - if (p && strtosize(p + 7, &offset) != 0) { + if (p && strtosize(p, &offset) != 0) { if (verbose) printf(_("mount: ignore %s " "(unparsable offset= option)\n"), mc->m.mnt_fsname); return -1; } + free(p); if (is_mounted_same_loopfile(mc->m.mnt_dir, mc->m.mnt_fsname, offset)) goto yes; } diff --git a/mount/umount.c b/mount/umount.c index 079aa337..468fb601 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -455,26 +455,6 @@ contains(const char *list, const char *s) { return 0; } -/* - * If list contains "user=peter" and we ask for "user=", return "peter" - */ -static char * -get_value(const char *list, const char *s) { - const char *t; - int n = strlen(s); - - while (list && *list) { - if (strncmp(list, s, n) == 0) { - s = t = list+n; - while (*s && *s != ',') - s++; - return xstrndup(t, s-t); - } - while (*list && *list++ != ',') ; - } - return NULL; -} - /* check if @mc contains a loop device which is associated * with the @file in fs */ @@ -494,7 +474,7 @@ is_valid_loop(struct mntentchn *mc, struct mntentchn *fs) return 0; /* check for offset option in fstab */ - p = get_value(fs->m.mnt_opts, "offset="); + p = get_option_value(fs->m.mnt_opts, "offset="); if (p && strtosize(p, &offset)) { if (verbose > 1) printf(_("failed to parse 'offset=%s' options\n"), p); @@ -572,7 +552,8 @@ umount_file (char *arg) { char *uhelper = NULL; if (mc->m.mnt_opts) - uhelper = get_value(mc->m.mnt_opts, "uhelper="); + uhelper = get_option_value(mc->m.mnt_opts, + "uhelper="); if (uhelper) { int status = 0; if (check_special_umountprog(arg, arg, @@ -641,7 +622,7 @@ umount_file (char *arg) { options = mc->m.mnt_opts; if (!options) options = ""; - mtab_user = get_value(options, "user="); + mtab_user = get_option_value(options, "user="); if (user && mtab_user && streq (user, mtab_user)) ok = 1;