From 6b14ef4fcd65c518104d76516cb9e387c6a450fb Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Thu, 7 May 2015 18:49:18 +0100 Subject: setup_pkt_dpdk: validate device name There is a test odp_pktio_open("notthere', ) which should return fail. If we use atoi() in that function we need to validate if dev name has only digits. Signed-off-by: Maxim Uvarov [zoltan.kiss@linaro.org: improved the subject and message a bit] Signed-off-by: Zoltan Kiss --- platform/linux-dpdk/odp_packet_dpdk.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'platform/linux-dpdk/odp_packet_dpdk.c') diff --git a/platform/linux-dpdk/odp_packet_dpdk.c b/platform/linux-dpdk/odp_packet_dpdk.c index 95e3d54ee..43dbd3203 100644 --- a/platform/linux-dpdk/odp_packet_dpdk.c +++ b/platform/linux-dpdk/odp_packet_dpdk.c @@ -78,6 +78,18 @@ static const struct rte_eth_txconf tx_conf = { .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOOFFLOADS, }; +/* Test if s has only digits or not. Dpdk pktio uses only digits.*/ +static int _dpdk_netdev_is_valid(const char *s) +{ + while (*s) { + if (!isdigit(*s)) + return 0; + s++; + } + + return 1; +} + int setup_pkt_dpdk(pkt_dpdk_t * const pkt_dpdk, const char *netdev, odp_pool_t pool) { @@ -94,6 +106,10 @@ int setup_pkt_dpdk(pkt_dpdk_t * const pkt_dpdk, const char *netdev, ODP_DBG("dpdk netdev: %s\n", netdev); ODP_DBG("dpdk pool: %lx\n", pool); + + if (!_dpdk_netdev_is_valid(netdev)) + return -1; + portid = atoi(netdev); pkt_dpdk->portid = portid; pkt_dpdk->pool = pool; -- cgit v1.2.3