summaryrefslogtreecommitdiffstats
path: root/libmount/src/fs.c
diff options
context:
space:
mode:
authorKarel Zak2013-04-12 12:35:34 +0200
committerKarel Zak2013-04-12 12:35:34 +0200
commit4569bbeab783632c81ee14793da84b3e29444543 (patch)
treeb165e3f418600bef11edbd962bc7f76b9d95113f /libmount/src/fs.c
parentbuild-sys: release++ (v2.23-rc2) (diff)
downloadkernel-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/fs.c')
-rw-r--r--libmount/src/fs.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/libmount/src/fs.c b/libmount/src/fs.c
index bb9006dee..c95cdc7e7 100644
--- a/libmount/src/fs.c
+++ b/libmount/src/fs.c
@@ -131,7 +131,6 @@ struct libmnt_fs *mnt_copy_fs(struct libmnt_fs *dest,
if (!src)
return NULL;
-
if (!dest) {
dest = mnt_new_fs();
if (!dest)
@@ -197,6 +196,7 @@ struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs)
{
struct libmnt_fs *n = mnt_new_fs();
+ assert(fs);
if (!n)
return NULL;
@@ -249,6 +249,7 @@ err:
*/
void *mnt_fs_get_userdata(struct libmnt_fs *fs)
{
+ assert(fs);
return fs ? fs->userdata : NULL;
}
@@ -263,6 +264,7 @@ void *mnt_fs_get_userdata(struct libmnt_fs *fs)
*/
int mnt_fs_set_userdata(struct libmnt_fs *fs, void *data)
{
+ assert(fs);
if (!fs)
return -EINVAL;
fs->userdata = data;
@@ -303,6 +305,7 @@ const char *mnt_fs_get_srcpath(struct libmnt_fs *fs)
*/
const char *mnt_fs_get_source(struct libmnt_fs *fs)
{
+ assert(fs);
return fs ? fs->source : NULL;
}
@@ -346,6 +349,7 @@ int mnt_fs_set_source(struct libmnt_fs *fs, const char *source)
char *p = NULL;
int rc;
+ assert(fs);
if (!fs)
return -EINVAL;
@@ -375,6 +379,7 @@ int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path)
{
const char *p;
+ assert(fs);
if (!fs)
return 0;
@@ -401,6 +406,7 @@ int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path)
*/
int mnt_fs_streq_target(struct libmnt_fs *fs, const char *path)
{
+ assert(fs);
return fs && streq_except_trailing_slash(mnt_fs_get_target(fs), path);
}
@@ -439,6 +445,7 @@ int mnt_fs_streq_target(struct libmnt_fs *fs, const char *path)
*/
int mnt_fs_get_tag(struct libmnt_fs *fs, const char **name, const char **value)
{
+ assert(fs);
if (fs == NULL || !fs->tagname)
return -EINVAL;
if (name)
@@ -474,7 +481,6 @@ int mnt_fs_set_target(struct libmnt_fs *fs, const char *target)
char *p = NULL;
assert(fs);
-
if (!fs)
return -EINVAL;
if (target) {
@@ -506,6 +512,7 @@ static int mnt_fs_get_flags(struct libmnt_fs *fs)
*/
int mnt_fs_get_propagation(struct libmnt_fs *fs, unsigned long *flags)
{
+ assert(fs);
if (!fs || !flags)
return -EINVAL;
@@ -547,6 +554,7 @@ int mnt_fs_is_kernel(struct libmnt_fs *fs)
*/
int mnt_fs_is_swaparea(struct libmnt_fs *fs)
{
+ assert(fs);
return mnt_fs_get_flags(fs) & MNT_FS_SWAP;
}
@@ -558,6 +566,7 @@ int mnt_fs_is_swaparea(struct libmnt_fs *fs)
*/
int mnt_fs_is_pseudofs(struct libmnt_fs *fs)
{
+ assert(fs);
return mnt_fs_get_flags(fs) & MNT_FS_PSEUDO;
}
@@ -569,6 +578,7 @@ int mnt_fs_is_pseudofs(struct libmnt_fs *fs)
*/
int mnt_fs_is_netfs(struct libmnt_fs *fs)
{
+ assert(fs);
return mnt_fs_get_flags(fs) & MNT_FS_NET;
}
@@ -622,6 +632,7 @@ int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype)
{
char *p = NULL;
+ assert(fs);
if (!fs)
return -EINVAL;
if (fstype) {
@@ -700,9 +711,7 @@ char *mnt_fs_strdup_options(struct libmnt_fs *fs)
char *res;
assert(fs);
-
errno = 0;
-
if (fs->optstr)
return strdup(fs->optstr);
@@ -758,7 +767,6 @@ int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr)
char *v = NULL, *f = NULL, *u = NULL, *n = NULL;
assert(fs);
-
if (!fs)
return -EINVAL;
if (optstr) {
@@ -801,7 +809,6 @@ int mnt_fs_append_options(struct libmnt_fs *fs, const char *optstr)
int rc;
assert(fs);
-
if (!fs)
return -EINVAL;
if (!optstr)
@@ -842,7 +849,6 @@ int mnt_fs_prepend_options(struct libmnt_fs *fs, const char *optstr)
int rc;
assert(fs);
-
if (!fs)
return -EINVAL;
if (!optstr)
@@ -932,6 +938,7 @@ int mnt_fs_set_attributes(struct libmnt_fs *fs, const char *optstr)
{
char *p = NULL;
+ assert(fs);
if (!fs)
return -EINVAL;
if (optstr) {
@@ -974,6 +981,7 @@ int mnt_fs_append_attributes(struct libmnt_fs *fs, const char *optstr)
*/
int mnt_fs_prepend_attributes(struct libmnt_fs *fs, const char *optstr)
{
+ assert(fs);
if (!fs)
return -EINVAL;
if (!optstr)
@@ -1235,6 +1243,7 @@ int mnt_fs_get_option(struct libmnt_fs *fs, const char *name,
{
char rc = 1;
+ assert(fs);
if (!fs)
return -EINVAL;
if (fs->fs_optstr)
@@ -1260,6 +1269,9 @@ int mnt_fs_get_attribute(struct libmnt_fs *fs, const char *name,
{
char rc = 1;
+ assert(fs);
+ if (!fs)
+ return -EINVAL;
if (fs->attrs)
rc = mnt_optstr_get_option(fs->attrs, name, value, valsz);
return rc;
@@ -1286,6 +1298,7 @@ int mnt_fs_match_target(struct libmnt_fs *fs, const char *target,
{
int rc = 0;
+ assert(fs);
if (!fs || !target || !fs->target)
return 0;
@@ -1330,6 +1343,7 @@ int mnt_fs_match_source(struct libmnt_fs *fs, const char *source,
char *cn;
const char *src, *t, *v;
+ assert(fs);
if (!fs)
return 0;
@@ -1403,6 +1417,7 @@ int mnt_fs_match_source(struct libmnt_fs *fs, const char *source,
*/
int mnt_fs_match_fstype(struct libmnt_fs *fs, const char *types)
{
+ assert(fs);
return mnt_match_fstype(fs->fstype, types);
}
@@ -1418,6 +1433,7 @@ int mnt_fs_match_fstype(struct libmnt_fs *fs, const char *types)
*/
int mnt_fs_match_options(struct libmnt_fs *fs, const char *options)
{
+ assert(fs);
return mnt_match_options(mnt_fs_get_options(fs), options);
}
@@ -1430,7 +1446,7 @@ int mnt_fs_match_options(struct libmnt_fs *fs, const char *options)
*/
int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file)
{
- if (!fs)
+ if (!fs || !file)
return -EINVAL;
fprintf(file, "------ fs: %p\n", fs);
fprintf(file, "source: %s\n", mnt_fs_get_source(fs));
@@ -1514,6 +1530,8 @@ int mnt_fs_to_mntent(struct libmnt_fs *fs, struct mntent **mnt)
int rc;
struct mntent *m;
+ assert(fs);
+ assert(mnt);
if (!fs || !mnt)
return -EINVAL;