[PATCH] editors: fix potential deref-of-null

Maks Mishin maks.mishinfz at gmail.com
Tue Jan 21 18:08:51 UTC 2025


The libc standard does not define the behavior 
when passing a NULL value as a pathname value to an open() call, 
so a NULL check for the fn pointer has been added.

Signed-off-by: Maks Mishin <maks.mishinFZ at gmail.com>
---
 editors/vi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/editors/vi.c b/editors/vi.c
index 34932f60c..284630ef4 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1990,6 +1990,9 @@ static int file_insert(const char *fn, char *p, int initial)
 	if (p > end)
 		p = end;
 
+	if (fn == NULL)
+		return cnt;
+
 	fd = open(fn, O_RDONLY);
 	if (fd < 0) {
 		if (!initial)
-- 
2.43.0



More information about the busybox mailing list