Skip to content

Commit 08bcd73

Browse files
committed
exec_am_broadcast: fix NULL assignment of last element of child_argv
child_argv[argc+extra_args] is outside the allocated memory region, since it starts counting from 0. Seen with valgrind: ==22732== Invalid write of size 8 ==22732== at 0x5E876D4: exec_am_broadcast (termux-api.c:254) ==22732== Address 0x6033e10 is 0 bytes after a block of size 144 alloc'd ==22732== at 0x5CC9FB4: malloc (in /data/data/com.termux/files/usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so) ==22732== by 0x5E875BF: exec_am_broadcast (termux-api.c:231) ==22732== ==22732== Syscall param execve(argv) points to uninitialised byte(s) ==22732== at 0x5FEEB78: execve (in /apex/com.android.runtime/lib64/bionic/libc.so) ==22732== by 0x5F18023: execve (in /data/data/com.termux/files/usr/lib/libtermux-exec.so) ==22732== Address 0x6033e08 is 136 bytes inside a block of size 144 alloc'd ==22732== at 0x5CC9FB4: malloc (in /data/data/com.termux/files/usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so) ==22732== by 0x5E875BF: exec_am_broadcast (termux-api.c:231) ==22732== Uninitialised value was created by a heap allocation ==22732== at 0x5CC9FB4: malloc (in /data/data/com.termux/files/usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so) ==22732== by 0x5E875BF: exec_am_broadcast (termux-api.c:231)
1 parent eaf966b commit 08bcd73

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

termux-api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ _Noreturn void exec_am_broadcast(int argc, char** argv,
245245
memcpy(child_argv + extra_args, argv + 2, (argc-1) * sizeof(char*));
246246

247247
// End with NULL:
248-
child_argv[argc + extra_args] = NULL;
248+
child_argv[argc + extra_args - 1] = NULL;
249249

250250
// Use an a executable taking care of PATH and LD_LIBRARY_PATH:
251251
execv(PREFIX "/bin/am", child_argv);

0 commit comments

Comments
 (0)