diff options
author | Maxim Uvarov <maxim.uvarov@linaro.org> | 2015-05-07 18:49:18 +0100 |
---|---|---|
committer | Zoltan Kiss <zoltan.kiss@linaro.org> | 2015-05-07 18:49:18 +0100 |
commit | 6b14ef4fcd65c518104d76516cb9e387c6a450fb (patch) | |
tree | 1dd8c98ffbf5a2ce88f951cf02f4b1c61dfd3400 /platform/linux-dpdk/odp_packet_dpdk.c | |
parent | e713c0e531b57c55ad647bc5a9eb0ca7e96cd611 (diff) |
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 <maxim.uvarov@linaro.org>
[zoltan.kiss@linaro.org: improved the subject and message a bit]
Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
Diffstat (limited to 'platform/linux-dpdk/odp_packet_dpdk.c')
-rw-r--r-- | platform/linux-dpdk/odp_packet_dpdk.c | 16 |
1 files changed, 16 insertions, 0 deletions
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; |