Skip to content

Commit 512a252

Browse files
committed
termux-api: handle malloc errors
malloc might fail to allocate memory for child_argv. Ensure it was successfully allocated before trying to set its elements.
1 parent 530f292 commit 512a252

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

termux-api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ _Noreturn void exec_am_broadcast(int argc, char** argv,
248248

249249
int const extra_args = 15; // Including ending NULL.
250250
char** child_argv = malloc((sizeof(char*)) * (argc + extra_args));
251+
if (child_argv == NULL) {
252+
perror("malloc failed for am child args");
253+
exit(1);
254+
}
251255

252256
child_argv[0] = "am";
253257
child_argv[1] = "broadcast";

0 commit comments

Comments
 (0)