Skip to content

Commit 41bfd44

Browse files
author
Davidlohr Bueso
committed
examples: fix static analyzer warnings in fmapi-mctp
Fix two issues caught by static analysis: 1. Null pointer passed to execvp(): Add validation for argc, argv, and argv[0] before calling execute_cmd() to ensure non-null arguments. 2. Use of memory after free: Remove free(ext_list) calls from send_add() and send_release() error paths. These functions don't own ext_list - the caller allocates it and is responsible for freeing it. The original code caused use-after-free when the loop continued after a failed send, and potential double-free at exit_free_ctx. Co-Authored-By: Claude AI Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
1 parent ff96018 commit 41bfd44

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

examples/fmapi-mctp.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ int send_add(int num_extents, extent *ext_list, struct cxlmi_endpoint *ep)
125125
add_req = calloc(1, sizeof(*add_req) +
126126
num_extents * sizeof(add_req->extents[0]));
127127

128-
if (!add_req) {
129-
free(ext_list);
128+
if (!add_req)
130129
return -1;
131-
}
132130

133131
add_req->host_id = 0;
134132
add_req->selection_policy = CXL_EXTENT_SELECTION_POLICY_PRESCRIPTIVE;
@@ -165,10 +163,8 @@ int send_release(int num_extents, extent *ext_list, struct cxlmi_endpoint *ep)
165163
release_req = calloc(1, sizeof(*release_req) +
166164
num_extents * sizeof(release_req->extents[0]));
167165

168-
if (!release_req) {
169-
free(ext_list);
166+
if (!release_req)
170167
return -1;
171-
}
172168

173169
release_req->host_id = 0;
174170
release_req->flags = CXL_EXTENT_REMOVAL_POLICY_PRESCRIPTIVE;
@@ -378,7 +374,7 @@ static int create_dax_device(void) {
378374

379375
argc = split_cmd_to_argv(DAX_DEVICE_CMDS[i], &argv);
380376

381-
if (argc < 0) {
377+
if (argc <= 0 || !argv || !argv[0]) {
382378
printf("Failed to split command\n");
383379
return -1;
384380
}

0 commit comments

Comments
 (0)