diff options
| author | Hauke Mehrtens | 2026-05-31 15:21:18 +0000 |
|---|---|---|
| committer | Hauke Mehrtens | 2026-06-03 23:19:35 +0000 |
| commit | dc091afa58602e487cc72e3fe631cf97bec220d7 (patch) | |
| tree | efcf84a5b81097c8adb846f8a8e46b36f288a343 | |
| parent | fb0302dc0e51e8e052609408f9c2a01b9337b510 (diff) | |
| download | rpcd-dc091afa58602e487cc72e3fe631cf97bec220d7.tar.gz | |
rpc-sys: packagelist: check calloc() result for world array
rpc_sys_packagelist() allocated the "world" pointer array with calloc()
and immediately dereferenced it ("world[0] = world_mmap") without
checking for allocation failure. Under memory pressure this would
dereference a NULL pointer and crash the daemon.
Bail out with UBUS_STATUS_UNKNOWN_ERROR on allocation failure, releasing
the mmap and the open status file first.
Assisted-by: Claude:claude-opus-4-8
Link: https://github.com/openwrt/rpcd/pull/34
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
| -rw-r--r-- | sys.c | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -280,6 +280,11 @@ rpc_sys_packagelist(struct ubus_context *ctx, struct ubus_object *obj, if (nstrs) { /* extra one in world for NULL sentinel */ world = (const char **)calloc(nstrs+1, sizeof(char *)); + if (!world) { + munmap(world_mmap, world_mmap_size); + fclose(f); + return UBUS_STATUS_UNKNOWN_ERROR; + } world[0] = world_mmap; for (istr = 1, s = world_mmap; *s; s++) { if (*s == '\n') { |