[4/9] cryptodev: fix segment fault when parse input args

Message ID 20230302075012.32423-5-fengchengwen@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series fix kvargs callback prototype not clearly defined |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen March 2, 2023, 7:50 a.m. UTC
  The rte_kvargs_process() was used to parse KV pairs, it also supports
to parse 'only keys' (e.g. socket_id) type. And the callback function
parameter 'value' is NULL when parsed 'only keys'.

This patch fixes segment fault when parse input args with 'only keys'
(e.g. socket_id,max_nb_queue_pairs).

Fixes: 9e6edea41805 ("cryptodev: add APIs to assist PMD initialisation")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/cryptodev/cryptodev_pmd.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Akhil Goyal March 2, 2023, 8:11 a.m. UTC | #1
> The rte_kvargs_process() was used to parse KV pairs, it also supports
> to parse 'only keys' (e.g. socket_id) type. And the callback function
> parameter 'value' is NULL when parsed 'only keys'.
> 
> This patch fixes segment fault when parse input args with 'only keys'
> (e.g. socket_id,max_nb_queue_pairs).
> 
> Fixes: 9e6edea41805 ("cryptodev: add APIs to assist PMD initialisation")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>

I would say, you can squash your 4/9 and 5/9 patch in a single commit.
As you are doing the same thing in both the patches.
  
fengchengwen March 2, 2023, 9:21 a.m. UTC | #2
On 2023/3/2 16:11, Akhil Goyal wrote:
>> The rte_kvargs_process() was used to parse KV pairs, it also supports
>> to parse 'only keys' (e.g. socket_id) type. And the callback function
>> parameter 'value' is NULL when parsed 'only keys'.
>>
>> This patch fixes segment fault when parse input args with 'only keys'
>> (e.g. socket_id,max_nb_queue_pairs).
>>
>> Fixes: 9e6edea41805 ("cryptodev: add APIs to assist PMD initialisation")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> Acked-by: Akhil Goyal <gakhil@marvell.com>
> 
> I would say, you can squash your 4/9 and 5/9 patch in a single commit.
> As you are doing the same thing in both the patches.

The cause of the problem is the same but the symptom is different, so I split two commit.

It's okay to squash.

> .
>
  

Patch

diff --git a/lib/cryptodev/cryptodev_pmd.c b/lib/cryptodev/cryptodev_pmd.c
index 77b269f312..4122000839 100644
--- a/lib/cryptodev/cryptodev_pmd.c
+++ b/lib/cryptodev/cryptodev_pmd.c
@@ -38,6 +38,10 @@  rte_cryptodev_pmd_parse_uint_arg(const char *key __rte_unused,
 {
 	int i;
 	char *end;
+
+	if (value == NULL || extra_args == NULL)
+		return -EINVAL;
+
 	errno = 0;
 
 	i = strtol(value, &end, 10);