Skip to contentSkip to conversation

mount.nfs: fix NULL pointer derefernce in nfs_parse_square_bracket

PATCH In review Zhi Li 2 participants 2 messages Oct 21, 2022 – Oct 24, 2022

Subsystems (2)
lore
Share & tools
lore

Zhi Li

author
#0 lore raw

PATCH 1/1 mount.nfs: fix NULL pointer derefernce in nfs_parse_square_bracket

In function nfs_parse_square_bracket, hostname could be NULL, dereferencing it in free(*hostname) may cause an unexpected segfault.

---
 utils/mount/parse_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
utils/mount/parse_dev.c +2 -1
index 0d3bcb95..2ade5d5d 100644
@@ -170,7 +170,8 @@ static int nfs_parse_square_bracket(const char *dev,
 	if (pathname) {
 		*pathname = strndup(cbrace, path_len);
 		if (*pathname == NULL) {
-			free(*hostname);
+			if (hostname)
+				free(*hostname);
 			return nfs_pdn_nomem_err();
 		}
 	}
Signature · 1 line
2.37.3
#1 lore raw
Quoted 5 lines · Zhi Li

In function nfs_parse_square_bracket, hostname could be NULL, dereferencing it in free(*hostname) may cause an unexpected segfault.

Committed...

steved.

Quoted 18 lines
---
  utils/mount/parse_dev.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
utils/mount/parse_dev.c +2 -1
index 0d3bcb95..2ade5d5d 100644
@@ -170,7 +170,8 @@ static int nfs_parse_square_bracket(const char *dev,
  	if (pathname) {
  		*pathname = strndup(cbrace, path_len);
  		if (*pathname == NULL) {
-			free(*hostname);
+			if (hostname)
+				free(*hostname);
  			return nfs_pdn_nomem_err();
  		}
  	}