From 0fabec8c7fda554b79327d8713352e7a07539895 Mon Sep 17 00:00:00 2001
From: AntonMoryakov <ant.v.moryakov@gmail.com>
Date: Tue, 14 Jan 2025 18:06:49 +0300
Subject: [PATCH] sys-utils: fix add NULL check for mnt_fs_get_target return
 value

The static analyzer flagged a potential issue: the return value of
mnt_fs_get_target(fs) could be NULL, but it was dereferenced without
a check. This could lead to undefined behavior.

Added a NULL check before using the tgt pointer. If tgt is NULL,
the current iteration is skipped.

ChanChanges:
- Added if (!tgt) check before using tgt.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>

Reference:https://github.com/util-linux/util-linux/commit/0fabec8c7fda554b79327d8713352e7a07539895
Conflict:NA
---
 sys-utils/lsns.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index 500bc013..93bbd758 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -1132,6 +1132,9 @@ static int nsfs_xasputs(char **str,
 
 		const char *tgt = mnt_fs_get_target(fs);
 
+		if(!tgt)
+			continue;
+
 		if (!*str)
 			xasprintf(str, "%s", tgt);
 
-- 
2.33.0

