diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-10-11 19:33:13 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-10-13 17:56:54 -0400 |
commit | 7ff7394d9e4e9189c30fd018235e6b1728c6f2d0 (patch) | |
tree | 37a98cdb42d8b62b56aeb6fad7fd00299449d38d /src/core | |
parent | fb1316462952d17d6ebf19c3f093b730c13016a7 (diff) |
Never call qsort on potentially NULL arrays
This extends 62678ded 'efi: never call qsort on potentially
NULL arrays' to all other places where qsort is used and it
is not obvious that the count is non-zero.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/namespace.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/core/namespace.c b/src/core/namespace.c index 16b132ba56..936f36839b 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -222,7 +222,7 @@ int setup_namespace(char** read_write_dirs, strv_length(read_only_dirs) + strv_length(inaccessible_dirs) + (private_tmp ? 2 : 0); - BindMount *m, *mounts; + BindMount *m, *mounts = NULL; int r = 0; if (!mount_flags) @@ -231,27 +231,29 @@ int setup_namespace(char** read_write_dirs, if (unshare(CLONE_NEWNS) < 0) return -errno; - m = mounts = (BindMount *) alloca(n * sizeof(BindMount)); - if ((r = append_mounts(&m, read_write_dirs, READWRITE)) < 0 || - (r = append_mounts(&m, read_only_dirs, READONLY)) < 0 || - (r = append_mounts(&m, inaccessible_dirs, INACCESSIBLE)) < 0) - return r; + if (n) { + m = mounts = (BindMount *) alloca(n * sizeof(BindMount)); + if ((r = append_mounts(&m, read_write_dirs, READWRITE)) < 0 || + (r = append_mounts(&m, read_only_dirs, READONLY)) < 0 || + (r = append_mounts(&m, inaccessible_dirs, INACCESSIBLE)) < 0) + return r; + + if (private_tmp) { + m->path = "/tmp"; + m->mode = PRIVATE_TMP; + m++; + + m->path = "/var/tmp"; + m->mode = PRIVATE_VAR_TMP; + m++; + } - if (private_tmp) { - m->path = "/tmp"; - m->mode = PRIVATE_TMP; - m++; + assert(mounts + n == m); - m->path = "/var/tmp"; - m->mode = PRIVATE_VAR_TMP; - m++; + qsort(mounts, n, sizeof(BindMount), mount_path_compare); + drop_duplicates(mounts, &n); } - assert(mounts + n == m); - - qsort(mounts, n, sizeof(BindMount), mount_path_compare); - drop_duplicates(mounts, &n); - /* Remount / as SLAVE so that nothing now mounted in the namespace shows up in the parent */ if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL) < 0) |