diff options
author | Karel Zak | 2013-04-12 12:35:34 +0200 |
---|---|---|
committer | Karel Zak | 2013-04-12 12:35:34 +0200 |
commit | 4569bbeab783632c81ee14793da84b3e29444543 (patch) | |
tree | b165e3f418600bef11edbd962bc7f76b9d95113f /libmount/src/optstr.c | |
parent | build-sys: release++ (v2.23-rc2) (diff) | |
download | kernel-qcow2-util-linux-4569bbeab783632c81ee14793da84b3e29444543.tar.gz kernel-qcow2-util-linux-4569bbeab783632c81ee14793da84b3e29444543.tar.xz kernel-qcow2-util-linux-4569bbeab783632c81ee14793da84b3e29444543.zip |
libmount: fix mount.nfs segfault, rely on assert() rather than on nonnull
We use
mnt_optstr_append_option(&o, mnt_fs_get_vfs_options(fs), NULL);
in mount.nfs, unfortunately mnt_optstr_append_option() has been marked
ass nonnull(1, 2). That's wrong because append and prepend should
robust enough to accept NULL as option name.
The patch also removes almost all __attribute__((nonnull). It seems
better to rely on assert() to have usable feedback. In many cases
(nonnull) is premature optimization for the library. This attribute
makes sense for things like strlen() or so...
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=948274
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/optstr.c')
-rw-r--r-- | libmount/src/optstr.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c index a3a5d0a08..5e9e70807 100644 --- a/libmount/src/optstr.c +++ b/libmount/src/optstr.c @@ -169,8 +169,7 @@ int mnt_optstr_next_option(char **optstr, char **name, size_t *namesz, return mnt_optstr_parse_next(optstr, name, namesz, value, valuesz); } -static int __attribute__((nonnull(1, 2))) -__mnt_optstr_append_option(char **optstr, +static int __mnt_optstr_append_option(char **optstr, const char *name, size_t nsz, const char *value, size_t vsz) { @@ -180,6 +179,7 @@ __mnt_optstr_append_option(char **optstr, assert(name); assert(*name); assert(nsz); + assert(optstr); osz = *optstr ? strlen(*optstr) : 0; @@ -225,6 +225,8 @@ int mnt_optstr_append_option(char **optstr, const char *name, const char *value) { size_t vsz, nsz; + assert(optstr); + if (!name || !*name) return 0; @@ -248,6 +250,11 @@ int mnt_optstr_prepend_option(char **optstr, const char *name, const char *value int rc = 0; char *tmp = *optstr; + assert(optstr); + + if (!name || !*name) + return 0; + *optstr = NULL; rc = mnt_optstr_append_option(optstr, name, value); @@ -282,6 +289,9 @@ int mnt_optstr_get_option(const char *optstr, const char *name, struct libmnt_optloc ol; int rc; + assert(optstr); + assert(name); + mnt_init_optloc(&ol); rc = mnt_optstr_locate_option((char *) optstr, name, &ol); @@ -307,8 +317,12 @@ int mnt_optstr_get_option(const char *optstr, const char *name, int mnt_optstr_deduplicate_option(char **optstr, const char *name) { int rc; - char *begin = NULL, *end = NULL, *opt = *optstr; + char *begin = NULL, *end = NULL, *opt; + assert(optstr); + assert(name); + + opt = *optstr; do { struct libmnt_optloc ol; @@ -421,6 +435,9 @@ int mnt_optstr_set_option(char **optstr, const char *name, const char *value) char *nameend; int rc = 1; + assert(optstr); + assert(name); + if (!optstr) return -EINVAL; @@ -467,6 +484,9 @@ int mnt_optstr_remove_option(char **optstr, const char *name) struct libmnt_optloc ol; int rc; + assert(optstr); + assert(name); + mnt_init_optloc(&ol); rc = mnt_optstr_locate_option(*optstr, name, &ol); |