]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: use strdup_between_structs()
authorKarel Zak <kzak@redhat.com>
Wed, 23 Oct 2019 10:30:19 +0000 (12:30 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 31 Oct 2019 11:25:08 +0000 (12:25 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/fs.c

index 8e1292522354050e4b6cc66b215ef8e371955980..fd6cfc8369daa87dcffe69ddcd673247da7356da 100644 (file)
@@ -218,11 +218,11 @@ struct libmnt_context *mnt_copy_context(struct libmnt_context *o)
        n->mtab = o->utab;
        mnt_ref_table(n->utab);
 
-       if (o->tgt_prefix && !(n->tgt_prefix = strdup(o->tgt_prefix)))
+       if (strdup_between_structs(n, o, tgt_prefix))
                goto failed;
-       if (o->helper && !(n->helper = strdup(o->helper)))
+       if (strdup_between_structs(n, o, helper))
                goto failed;
-       if (o->orig_user && !(n->orig_user = strdup(o->orig_user)))
+       if (strdup_between_structs(n, o, orig_user))
                goto failed;
 
        n->mountflags = o->mountflags;
index 4126ee9dce85b3d67b23e90b263bdded2418c25c..bcc8273488c19afdeb7464b49035e41a19555fef 100644 (file)
@@ -153,6 +153,8 @@ static inline int update_str(char **dest, const char *src)
        return 0;
 }
 
+/* This function do NOT overwrite (replace) the string in @new, the string in
+ * the @new has to be NULL otherwise this is no-op */
 static inline int cpy_str_at_offset(void *new, const void *old, size_t offset)
 {
        char **o = (char **) ((char *) old + offset);
@@ -253,11 +255,11 @@ struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs)
        if (!n)
                return NULL;
 
-       if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, source)))
+       if (strdup_between_structs(n, fs, source))
                goto err;
-       if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, target)))
+       if (strdup_between_structs(n, fs, target))
                goto err;
-       if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, fstype)))
+       if (strdup_between_structs(n, fs, fstype))
                goto err;
 
        if (fs->vfs_optstr) {
@@ -276,7 +278,7 @@ struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs)
                n->user_optstr = p;
        }
 
-       if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, fs_optstr)))
+       if (strdup_between_structs(n, fs, fs_optstr))
                goto err;
 
        /* we cannot copy original optstr, the new optstr has to be without