From 84f46d1f6725980697e5a442b06ececd9ceb6576 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 18 May 2019 21:46:08 +0100 Subject: sfdisk: remove unnecessary size check [cppcheck] Following warning is false positive. Size of the buffer is defined using BUFSIZ, and so the strncpy() will never overwrite the last byte that is initialized to zero in get_user_reply(). [disk-utils/sfdisk.c:137] -> [disk-utils/sfdisk.c:136]: (warning) Either the condition 'bufsz!=0' is redundant or strncpy() argument nr 3 can have invalid value. The value is -1 but the valid values are '0:'. Signed-off-by: Sami Kerola --- disk-utils/sfdisk.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 4a9640d0e..83f3cf8f7 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -134,8 +134,6 @@ static int get_user_reply(const char *prompt, char *buf, size_t bufsz) if (!p) return 1; strncpy(buf, p, bufsz - 1); - if (bufsz != 0) - buf[bufsz - 1] = '\0'; free(p); } else #endif -- cgit v1.2.3-55-g7522 From 4f807791eee8ead3f38f1dce76f748fa0773f9a6 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 18 May 2019 22:09:25 +0100 Subject: lib/mangle: fix possible null pointer dereference [cppcheck] Fix effects code that is used when testing util-linux, so quite low impact. Signed-off-by: Sami Kerola --- lib/mangle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mangle.c b/lib/mangle.c index b514cd8d3..87802fbda 100644 --- a/lib/mangle.c +++ b/lib/mangle.c @@ -155,9 +155,9 @@ int main(int argc, char *argv[]) } x = strdup(argv[2]); - unmangle_to_buffer(x, x, strlen(x) + 1); - if (x) { + unmangle_to_buffer(x, x, strlen(x) + 1); + printf("self-unmangled: '%s'\n", x); free(x); } -- cgit v1.2.3-55-g7522 From cbcedf6ba83b0929ad21e227db62883886d2ccce Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 18 May 2019 22:14:20 +0100 Subject: libmount: avoid possible null pointer dereference [cppcheck] [libmount/src/monitor.c:797]: (warning) Possible null pointer dereference: me Signed-off-by: Sami Kerola --- libmount/src/monitor.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libmount/src/monitor.c b/libmount/src/monitor.c index 2383a734a..730c8bdea 100644 --- a/libmount/src/monitor.c +++ b/libmount/src/monitor.c @@ -794,14 +794,17 @@ int mnt_monitor_next_change(struct libmnt_monitor *mn, me = NULL; } - me->changed = 0; + if (me) { + me->changed = 0; - if (filename) - *filename = me->path; - if (type) - *type = me->type; + if (filename) + *filename = me->path; + if (type) + *type = me->type; - DBG(MONITOR, ul_debugobj(mn, " *** success [changed: %s]", me->path)); + DBG(MONITOR, ul_debugobj(mn, " *** success [changed: %s]", me->path)); + } else + return -EINVAL; return 0; /* success */ } -- cgit v1.2.3-55-g7522 From 6dd7b74b3ba1a9cea30f6406dce1f5108ec10f93 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 18 May 2019 22:25:11 +0100 Subject: lscpu: remove redundant condition check [cppcheck] [sys-utils/lscpu.c:1783] -> [sys-utils/lscpu.c:1785]: (warning) Either the condition 'desc' is redundant or there is possible null pointer dereference: desc. [sys-utils/lscpu.c:1840] -> [sys-utils/lscpu.c:1842]: (warning) Either the condition 'desc' is redundant or there is possible null pointer dereference: desc. Signed-off-by: Sami Kerola --- sys-utils/lscpu.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 9a5a1aa5b..dd5b86cb1 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -1778,10 +1778,12 @@ print_cpus_parsable(struct lscpu_desc *desc, int cols[], int ncols, int c; int cpu = real_cpu_num(desc, i); - if (!mod->offline && desc->online && !is_cpu_online(desc, cpu)) - continue; - if (!mod->online && desc->online && is_cpu_online(desc, cpu)) - continue; + if (desc->online) { + if (!mod->offline && !is_cpu_online(desc, cpu)) + continue; + if (!mod->online && is_cpu_online(desc, cpu)) + continue; + } if (desc->present && !is_cpu_present(desc, cpu)) continue; for (c = 0; c < ncols; c++) { @@ -1835,10 +1837,12 @@ print_cpus_readable(struct lscpu_desc *desc, int cols[], int ncols, struct libscols_line *line; int cpu = real_cpu_num(desc, i); - if (!mod->offline && desc->online && !is_cpu_online(desc, cpu)) - continue; - if (!mod->online && desc->online && is_cpu_online(desc, cpu)) - continue; + if (desc->online) { + if (!mod->offline && !is_cpu_online(desc, cpu)) + continue; + if (!mod->online && is_cpu_online(desc, cpu)) + continue; + } if (desc->present && !is_cpu_present(desc, cpu)) continue; -- cgit v1.2.3-55-g7522 From ff09a5129af18e9d26ffe6dae90f2380d9a0f771 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 18 May 2019 22:36:44 +0100 Subject: sulogin: fix variable / function shadowing [cppcheck] [login-utils/sulogin.c:398] -> [login-utils/sulogin.c:171]: (style) Local variable set shadows outer function [login-utils/sulogin.c:398] -> [login-utils/sulogin.c:830]: (style) Local variable set shadows outer function Signed-off-by: Sami Kerola --- login-utils/sulogin.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c index 549870d22..9091caf14 100644 --- a/login-utils/sulogin.c +++ b/login-utils/sulogin.c @@ -168,16 +168,17 @@ static void tcinit(struct console *con) tio->c_cc[VMIN] = 1; if (ioctl(fd, TIOCGWINSZ, &ws) == 0) { - int set = 0; + int update = 0; + if (ws.ws_row == 0) { ws.ws_row = 24; - set++; + update++; } if (ws.ws_col == 0) { ws.ws_col = 80; - set++; + update++; } - if (set) + if (update) ignore_result( ioctl(fd, TIOCSWINSZ, &ws) ); } -- cgit v1.2.3-55-g7522 From 9abc8a42aa28dac93dba2734a532d71a7bef3521 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 18 May 2019 22:39:58 +0100 Subject: wipefs: fix variable / function shadowing [cppcheck] [misc-utils/wipefs.c:636] -> [misc-utils/wipefs.c:310]: (style) Local variable usage shadows outer function Signed-off-by: Sami Kerola --- misc-utils/wipefs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index 78e5ac376..be728279b 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -307,7 +307,7 @@ static struct wipe_desc *get_desc_for_probe(struct wipe_control *ctl, loff_t *offset, size_t *len) { - const char *off, *type, *mag, *p, *usage = NULL; + const char *off, *type, *mag, *p, *use = NULL; struct wipe_desc *wp; int rc, ispt = 0; @@ -328,7 +328,7 @@ static struct wipe_desc *get_desc_for_probe(struct wipe_control *ctl, rc = blkid_probe_lookup_value(pr, "PTMAGIC", &mag, len); if (rc) return NULL; - usage = N_("partition-table"); + use = N_("partition-table"); ispt = 1; } else return NULL; @@ -357,8 +357,8 @@ static struct wipe_desc *get_desc_for_probe(struct wipe_control *ctl, if (!wp) return NULL; - if (usage || blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0) - wp->usage = xstrdup(usage); + if (use || blkid_probe_lookup_value(pr, "USAGE", &use, NULL) == 0) + wp->usage = xstrdup(use); wp->type = xstrdup(type); wp->on_disk = 1; -- cgit v1.2.3-55-g7522 From cc7ffe129d7c01eb3d4bf650e70b6befef6e1e19 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 18 May 2019 22:56:15 +0100 Subject: lib/colors: remove redundant if statement Signed-off-by: Sami Kerola --- lib/colors.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/colors.c b/lib/colors.c index ecec0ac30..26f3c81f7 100644 --- a/lib/colors.c +++ b/lib/colors.c @@ -662,11 +662,9 @@ static int colors_terminal_is_ready(void) if (setupterm(NULL, STDOUT_FILENO, &ret) != 0 || ret != 1) goto none; ncolors = tigetnum("colors"); - if (ncolors <= 2) - goto none; } #endif - if (ncolors != -1) { + if (1 < ncolors) { DBG(CONF, ul_debug("terminal is ready (supports %d colors)", ncolors)); return 1; } -- cgit v1.2.3-55-g7522