Skip to content

Commit bd569ee

Browse files
[FIX] size of IOp buffer too small + strchr segfault (#11)
* [FIX] Fix issue with iop_push parameters types New Iop format for multi-hpu support required more words * [FIX] prevent potential segfault from strchr on string coming from AMC --------- Co-authored-by: Baptiste Roux <baptiste.roux@zama.ai>
1 parent 1dce0b4 commit bd569ee

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

sw/AMI/driver/ami_iop_push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "ami_iop_push.h"
1313
#include "ami_amc_control.h"
1414

15-
int iop_push(struct amc_control_ctxt *amc_ctrl_ctxt, uint8_t *buf, uint8_t buf_len, uint32_t offset, bool dop) {
15+
int iop_push(struct amc_control_ctxt *amc_ctrl_ctxt, uint8_t *buf, uint32_t buf_len, uint32_t offset, bool dop) {
1616
int ret = SUCCESS;
1717
int i;
1818
uint32_t iopq_head = 0;

sw/AMI/driver/ami_iop_push.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
int iop_push(
1515
struct amc_control_ctxt *amc_ctrl_ctxt,
1616
uint8_t *buf,
17-
uint8_t buf_len,
17+
uint32_t buf_len,
1818
uint32_t offset,
1919
bool dop
2020
);

sw/AMI/driver/ami_log.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ void dump_amc_log(struct amc_control_ctxt *amc_ctrl_ctxt)
5656

5757
memcpy_fromio(&msg, (void*)log_msg_addr, sizeof(struct amc_msg_payload));
5858

59-
if(strchr(msg.buff, '\0') && strlen(msg.buff))
60-
AMI_AMC_LOG(amc_ctrl_ctxt, "%s", msg.buff);
59+
size_t safe_len = strnlen(msg.buff, sizeof(msg.buff));
60+
msg.buff[sizeof(msg.buff) - 1] = '\0';
61+
62+
if (safe_len > 0)
63+
AMI_AMC_LOG(amc_ctrl_ctxt, "%s", msg.buff);
6164

6265
i = (i + 1) % AMC_LOG_MAX_RECS;
6366
}

0 commit comments

Comments
 (0)