Skip to content

Commit 69edccc

Browse files
yliu80wenlingz
authored andcommitted
IOC Mediator: Add return value check for snprintf
Return value check for snprintf function. Tracked-On: #1401 Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Reviewed-by: Shuo Liu <shuo.a.liu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent cc89e52 commit 69edccc

File tree

1 file changed

+18
-4
lines changed
  • devicemodel/hw/platform

1 file changed

+18
-4
lines changed

devicemodel/hw/platform/ioc.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,9 +1550,13 @@ ioc_parse(const char *opts)
15501550
{
15511551
char *tmp;
15521552
char *param = strdup(opts);
1553+
int rc;
15531554

15541555
tmp = strtok(param, ",");
1555-
snprintf(virtual_uart_path, sizeof(virtual_uart_path), "%s", param);
1556+
rc = snprintf(virtual_uart_path, sizeof(virtual_uart_path), "%s", param);
1557+
if (rc < 0 || rc >= sizeof(virtual_uart_path))
1558+
WPRINTF("ioc gets incomplete virtual uart path:%s\r\n",
1559+
virtual_uart_path);
15561560
if (tmp != NULL) {
15571561
tmp = strtok(NULL, ",");
15581562
if (tmp != NULL) {
@@ -1575,6 +1579,7 @@ int
15751579
ioc_init(struct vmctx *ctx)
15761580
{
15771581
int i;
1582+
int rc;
15781583
struct ioc_dev *ioc;
15791584

15801585
IOC_LOG_INIT;
@@ -1668,7 +1673,10 @@ ioc_init(struct vmctx *ctx)
16681673
ARRAY_SIZE(wlist_tx_group_table));
16691674

16701675
/* Setup IOC rx members */
1671-
snprintf(ioc->rx_name, sizeof(ioc->rx_name), "ioc_rx");
1676+
rc = snprintf(ioc->rx_name, sizeof(ioc->rx_name), "ioc_rx");
1677+
if (rc < 0)
1678+
WPRINTF("%s", "ioc fails to set ioc_rx thread name\r\n");
1679+
16721680
ioc->ioc_dev_rx = cbc_rx_handler;
16731681
pthread_cond_init(&ioc->rx_cond, NULL);
16741682
pthread_mutex_init(&ioc->rx_mtx, NULL);
@@ -1683,7 +1691,10 @@ ioc_init(struct vmctx *ctx)
16831691
ioc->rx_config.wlist_grp_tbl = wlist_rx_group_table;
16841692

16851693
/* Setup IOC tx members */
1686-
snprintf(ioc->tx_name, sizeof(ioc->tx_name), "ioc_tx");
1694+
rc = snprintf(ioc->tx_name, sizeof(ioc->tx_name), "ioc_tx");
1695+
if (rc < 0)
1696+
WPRINTF("%s", "ioc fails to set ioc_tx thread name\r\n");
1697+
16871698
ioc->ioc_dev_tx = cbc_tx_handler;
16881699
pthread_cond_init(&ioc->tx_cond, NULL);
16891700
pthread_mutex_init(&ioc->tx_mtx, NULL);
@@ -1710,7 +1721,10 @@ ioc_init(struct vmctx *ctx)
17101721
if (ioc_create_thread(ioc->tx_name, &ioc->tx_tid, ioc_tx_thread,
17111722
(void *)ioc) < 0)
17121723
goto work_err;
1713-
snprintf(ioc->name, sizeof(ioc->name), "ioc_core");
1724+
rc = snprintf(ioc->name, sizeof(ioc->name), "ioc_core");
1725+
if (rc < 0)
1726+
WPRINTF("%s", "ioc fails to set ioc_core thread name\r\n");
1727+
17141728
if (ioc_create_thread(ioc->name, &ioc->tid, ioc_core_thread,
17151729
(void *)ioc) < 0)
17161730
goto work_err;

0 commit comments

Comments
 (0)