From 5119ef0a8335a7a9e3fde2b6990ed66e2c0b5974 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Mon, 1 Jul 2019 22:02:06 +0100 Subject: lib/ttyutils: avoid checking same thing twice Check cols and lines are not NULL only once. Signed-off-by: Sami Kerola --- lib/ttyutils.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/ttyutils.c b/lib/ttyutils.c index 166e49e11..8649f435a 100644 --- a/lib/ttyutils.c +++ b/lib/ttyutils.c @@ -47,16 +47,16 @@ int get_terminal_dimension(int *cols, int *lines) l = t_win.ts_lines; } #endif - - if (cols && c <= 0) - c = get_env_int("COLUMNS"); - if (lines && l <= 0) - l = get_env_int("LINES"); - - if (cols) + if (cols) { + if (c <= 0) + c = get_env_int("COLUMNS"); *cols = c; - if (lines) + } + if (lines) { + if (l <= 0) + l = get_env_int("LINES"); *lines = l; + } return 0; } -- cgit v1.2.3-55-g7522 From 34813bdd29cd2012bec61156286018ed9e13817a Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 12 Jul 2019 21:45:50 +0100 Subject: libfdisk: fix variable shadowing libfdisk/src/context.c:678:7: warning: declaration of ‘rc’ shadows a previous local [-Wshadow] Signed-off-by: Sami Kerola --- libfdisk/src/context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 3677648e9..770aa4d52 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -675,7 +675,7 @@ int fdisk_assign_device(struct fdisk_context *cxt, fd = open(fname, (readonly ? O_RDONLY : O_RDWR ) | O_CLOEXEC); if (fd < 0) { - int rc = -errno; + rc = -errno; DBG(CXT, ul_debugobj(cxt, "failed to assign device [rc=%d]", rc)); return rc; } -- cgit v1.2.3-55-g7522 From 371be858d74fe5562a403af75e596d7bd0042905 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 12 Jul 2019 21:56:52 +0100 Subject: libmount: fix potential null pointer dereference This is false positive warning, but lets silence it so that if and when warnings crop up they are easy to notice and take seriously. libmount/src/optstr.c:354:29: warning: potential null pointer dereference [-Wnull-dereference] Signed-off-by: Sami Kerola --- libmount/src/optstr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c index c0f438fe2..49fc9cc40 100644 --- a/libmount/src/optstr.c +++ b/libmount/src/optstr.c @@ -351,7 +351,9 @@ int mnt_optstr_deduplicate_option(char **optstr, const char *name) end = ol.end; opt = end && *end ? end + 1 : NULL; } - } while (rc == 0 && opt && *opt); + if (opt == NULL) + break; + } while (rc == 0 && *opt); return rc < 0 ? rc : begin ? 0 : 1; } -- cgit v1.2.3-55-g7522 From f3aded3fdb1e19818b05f205b74cd4bff7532811 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 12 Jul 2019 22:28:10 +0100 Subject: include/xalloc: ensure xstrdup() and xstrndup() returns nonnull attribute Turned out lsblk is passing null as argument to xstrdup(), so fix that and add assert() to make sure promise of not returning null is kept in future. Signed-off-by: Sami Kerola --- include/xalloc.h | 6 ++---- misc-utils/lsblk.c | 8 +++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/xalloc.h b/include/xalloc.h index 0129a85e2..48712a452 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -62,8 +62,7 @@ static inline char __attribute__((warn_unused_result)) __ul_returns_nonnull { char *ret; - if (!str) - return NULL; + assert(str); ret = strdup(str); @@ -77,8 +76,7 @@ xstrndup(const char *str, size_t size) { char *ret; - if (!str) - return NULL; + assert(str); ret = strndup(str, size); diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 3ce6da730..7ab9dc23c 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -774,8 +774,14 @@ static char *device_get_data( str = get_vfs_attribute(dev, id); break; case COL_TARGET: - str = xstrdup(lsblk_device_get_mountpoint(dev)); + { + char *s = lsblk_device_get_mountpoint(dev); + if (s) + str = xstrdup(s); + else + str = NULL; break; + } case COL_LABEL: prop = lsblk_device_get_properties(dev); if (prop && prop->label) -- cgit v1.2.3-55-g7522 From 9175f39075b130bce00ed4b0d23be90a1defa915 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 13 Jul 2019 09:31:06 +0100 Subject: libblkid: check number of test_blkid_save arguments correctly Without this running test_blkid_save without arguments will cause a crash when strdup() refers to none-exiting file name. Signed-off-by: Sami Kerola --- libblkid/src/save.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libblkid/src/save.c b/libblkid/src/save.c index 21308a9cf..bceaa1139 100644 --- a/libblkid/src/save.c +++ b/libblkid/src/save.c @@ -213,7 +213,7 @@ int main(int argc, char **argv) int ret; blkid_init_debug(BLKID_DEBUG_ALL); - if (argc > 2) { + if (argc != 2) { fprintf(stderr, "Usage: %s [filename]\n" "Test loading/saving a cache (filename)\n", argv[0]); exit(1); -- cgit v1.2.3-55-g7522 From f55dd4cc2dadfa74e5a207a4058489fa4d10387a Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 14 Jul 2019 10:17:32 +0100 Subject: libblkid: fix address sanitizer issues With aligned attribute many blkid tests fail with following error. So instead of aligning to 4K add padding that makes the struct same size without causing asan trip over. libblkid/src/superblocks/drbd.c:179:6: runtime error: member access within misaligned address 0x55913d7e6958 for type 'struct meta_data_on_disk_9', which requires 4096 byte alignment In zfs structure it seems compiler is adding padding, that does not mix well with be32_to_cpu() and other bit operations. libblkid/src/superblocks/zfs.c:109:23: runtime error: load of misaligned address 0x7ff6406540e4 for type 'uint32_t' (aka 'unsigned int'), which requires 8 byte alignment Signed-off-by: Sami Kerola --- libblkid/src/superblocks/drbd.c | 2 +- libblkid/src/superblocks/zfs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libblkid/src/superblocks/drbd.c b/libblkid/src/superblocks/drbd.c index 4ebaf1739..c27a8b384 100644 --- a/libblkid/src/superblocks/drbd.c +++ b/libblkid/src/superblocks/drbd.c @@ -109,7 +109,7 @@ struct meta_data_on_disk_9 { struct peer_dev_md_on_disk_9 peers[DRBD_PEERS_MAX]; uint64_t history_uuids[HISTORY_UUIDS]; - char padding[0] __attribute__((aligned(4096))); + uint8_t padding[2704]; } __attribute__((packed)); diff --git a/libblkid/src/superblocks/zfs.c b/libblkid/src/superblocks/zfs.c index 4d4b46d55..0af14fb65 100644 --- a/libblkid/src/superblocks/zfs.c +++ b/libblkid/src/superblocks/zfs.c @@ -58,7 +58,7 @@ struct nvuint64 { uint32_t nvu_type; uint32_t nvu_elem; uint64_t nvu_value; -}; +} __attribute__((packed)); struct nvlist { uint32_t nvl_unknown[3]; -- cgit v1.2.3-55-g7522