Skip to content

Commit 9f61b87

Browse files
committed
rpifwcrypto: Fix file handle leak in genkey error handling path
Also, fix the pointer casting in rpi_fw_cryto_gen_ecdsa_key and mbox_property to avoid an error with -O2 on GCC 14.
1 parent 4f639ab commit 9f61b87

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

rpifwcrypto/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ static int cmd_hmac(int argc, char *argv[])
226226
goto end;
227227

228228
fail_read:
229-
if (f)
230-
fclose(f);
231229
rc = -1;
232230
goto end;
233231
fail_write:
234232
rc = -1;
235233
goto end;
236234
end:
235+
if (f)
236+
fclose(f);
237237
return rc;
238238
}
239239

rpifwcrypto/rpifwcrypto.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,21 @@ static void mbox_close(int file_desc)
148148
close(file_desc);
149149
}
150150

151-
static int mbox_property(int file_desc, struct firmware_msg *msg)
151+
static int mbox_property(int file_desc, void *msg)
152152
{
153+
struct firmware_msg_header *hdr = (struct firmware_msg_header *)msg;
153154
int rc = ioctl(file_desc, IOCTL_MBOX_PROPERTY, msg);
154155
if (rc < 0)
155156
fprintf(stderr, "ioctl_mbox_property failed: %d\n", rc);
156157

157-
LOG_DEBUG("msg.hdr.code: %08x\n", msg->hdr.code);
158-
LOG_DEBUG("msg.hdr.buf_size: %d\n", msg->hdr.buf_size);
159-
LOG_DEBUG("msg.hdr.tag: %d\n", msg->hdr.tag);
160-
LOG_DEBUG("msg.hdr.tag_buf_size: %d\n", msg->hdr.tag_buf_size);
161-
LOG_DEBUG("msg.hdr.tag_req_resp_size: %d\n", msg->hdr.tag_req_resp_size);
158+
LOG_DEBUG("msg.hdr.code: %08x\n", hdr->code);
159+
LOG_DEBUG("msg.hdr.buf_size: %d\n", hdr->buf_size);
160+
LOG_DEBUG("msg.hdr.tag: %d\n", hdr->tag);
161+
LOG_DEBUG("msg.hdr.tag_buf_size: %d\n", hdr->tag_buf_size);
162+
LOG_DEBUG("msg.hdr.tag_req_resp_size: %d\n", hdr->tag_req_resp_size);
162163

163-
if (!(msg->hdr.code & VC_MAILBOX_ERROR) ||
164-
!(msg->hdr.tag_req_resp_size & VC_MAILBOX_ERROR))
164+
if (!(hdr->code & VC_MAILBOX_ERROR) ||
165+
!(hdr->tag_req_resp_size & VC_MAILBOX_ERROR))
165166
return -1;
166167

167168
return 0;

0 commit comments

Comments
 (0)