diff mbox series

[2/3] libss: fix possible NULL pointer dereferece on allocation failure

Message ID 20220217092500.40525-2-lczerner@redhat.com
State Accepted
Headers show
Series [1/3] resize2fs: remove unused variable 'c' | expand

Commit Message

Lukas Czerner Feb. 17, 2022, 9:24 a.m. UTC
Currently in ss_execute_command() we're missng a check to see if the
memory allocation was succesful. Fix it by adding SS_ET_ENOMEM error and
checking the return from malloc.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 lib/ss/execute_cmd.c | 2 ++
 lib/ss/ss_err.et     | 3 +++
 2 files changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/lib/ss/execute_cmd.c b/lib/ss/execute_cmd.c
index d443a468..0bcaa54d 100644
--- a/lib/ss/execute_cmd.c
+++ b/lib/ss/execute_cmd.c
@@ -171,6 +171,8 @@  int ss_execute_command(int sci_idx, register char *argv[])
 	for (argp = argv; *argp; argp++)
 		argc++;
 	argp = (char **)malloc((argc+1)*sizeof(char *));
+	if (!argp)
+		return(SS_ET_ENOMEM);
 	for (i = 0; i <= argc; i++)
 		argp[i] = argv[i];
 	i = really_execute_command(sci_idx, argc, &argp);
diff --git a/lib/ss/ss_err.et b/lib/ss/ss_err.et
index 80e9dfa4..f7238da0 100644
--- a/lib/ss/ss_err.et
+++ b/lib/ss/ss_err.et
@@ -36,4 +36,7 @@  ec	SS_ET_ESCAPE_DISABLED,
 ec	SS_ET_UNIMPLEMENTED,
 	"Sorry, this request is not yet implemented"
 
+ec	SS_ET_ENOMEM,
+	"Not enough memory"
+
 	end