From: Karel Zak Date: Wed, 23 Oct 2019 10:30:19 +0000 (+0200) Subject: libmount: use strdup_between_structs() X-Git-Tag: v2.35-rc1~82 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eee7ea558cde4dc9d00a9dfa3aca1ac55cef0798;p=thirdparty%2Futil-linux.git libmount: use strdup_between_structs() Signed-off-by: Karel Zak --- diff --git a/libmount/src/context.c b/libmount/src/context.c index 8e12925223..fd6cfc8369 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -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; diff --git a/libmount/src/fs.c b/libmount/src/fs.c index 4126ee9dce..bcc8273488 100644 --- a/libmount/src/fs.c +++ b/libmount/src/fs.c @@ -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