diff mbox series

[ndctl,5/8] util/help: check whether strdup returns NULL in exec_man_konqueror

Message ID 889d3dc7-2532-9f91-b0d8-5eeab45d6bb7@huawei.com (mailing list archive)
State New
Headers show
Series fix serverl issues reported by Coverity | expand

Commit Message

Zhiqiang Liu Nov. 6, 2020, 9:26 a.m. UTC
In exec_man_konqueror(), new is allocated by calling strdup(),
which may return NULL. We should check whether new is NULL before
using it.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
 util/help.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/util/help.c b/util/help.c
index 2d57fa1..f867944 100644
--- a/util/help.c
+++ b/util/help.c
@@ -44,8 +44,14 @@  static void exec_man_konqueror(const char *path, const char *page)
 		if (path) {
 			const char *file = strrchr(path, '/');
 			if (file && !strcmp(file + 1, "konqueror")) {
+				char *dest;
 				char *new = strdup(path);
-				char *dest = strrchr(new, '/');
+				if (!new) {
+					pr_err("strdup(path) fails.\n");
+					exit(1);
+				}
+
+				dest = strrchr(new, '/');

 				/* strlen("konqueror") == strlen("kfmclient") */
 				strcpy(dest + 1, "kfmclient");