From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1C1FA43255; Tue, 31 Oct 2023 21:58:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C47FA40DCE; Tue, 31 Oct 2023 21:58:50 +0100 (CET) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id E120440294 for ; Tue, 31 Oct 2023 21:58:49 +0100 (CET) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6b6f4c118b7so5598528b3a.0 for ; Tue, 31 Oct 2023 13:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1698785928; x=1699390728; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z3Jql36kyxuPNFa7i2EfN8M6EesVLpw79b81n605ngY=; b=ZaXPjqgQqYoZFMrxK2ANe/Kb7ugGmNK12pERkRW33pM6jzpi45LB3ukLei8vQW09qB Q8cF6y0OZ02hknmVJ/OBc1dr+oUa645L4JeCZ6WhwlrURb6QDnV+8JbQN+I2Xy+S0cpU unOQITS3sK1ZhQ/lY4GR0Zpocpn4+dAQO8TGyQul09RdvVKPyBjc1U4XDAp2DEt3sSuR 8+vsgjcbkCyyKy25iHnepV5ybNish+eAGwlShO0LEGK+XI1JL//nNUgxKqnCqVDAhdtq EIVUQlkkTSRCs9DuSN3TEWOPRqcMPEt6Fji4HcLR7kvo9MDvGn7MUp5XR2idu+yjJp3i VhXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698785928; x=1699390728; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z3Jql36kyxuPNFa7i2EfN8M6EesVLpw79b81n605ngY=; b=rtBdGKnOfLOjxgFm0FqW06jkrmn6mhac6V6S9juWc96aDdgKe/jsEgPRES+tALmtdj OdflKqFbFY9ksd0DQe6pJM4jWfUQFzaXSWSKxL0Mh5ErUo/PI1UtUcspcrYpKDTZ66hp NBbhOFgp7nZEPOOfIhLzcZbzgMauD0PQqE4h1Y1YXC7Xk4fRFZ+ADImITmRFDUqbufYV 086EAlwss8KoHvKLSJ4MXxVc2ijqpYIBz4mPuz3ShJyNof7NTsCmP/uiijJ2wZvtl24H 2R1Hp9rm0chvuB/cxEKPEbMwk5cYc2H0zRRgoy6ThpnKT4fusmVkkcjdumpaDIY1Lo5y DfOQ== X-Gm-Message-State: AOJu0YyVmnOVqyjKshkXt2r1vlhVeFD/SBf/SaWrnRE7LCfeNEe6Ysgx kYPqcleEV5eRuzbTttxD7FWWjHTcQxXVHFyDoZHfR5QB X-Google-Smtp-Source: AGHT+IFbE6amQx1pnI+WTOaDKPcpMahyAU/bqaOQOuasmx+Tc1gfEtxEP8Xns27yn9t9FgcdZ0Vg3g== X-Received: by 2002:a05:6a00:23d4:b0:6be:22db:7a13 with SMTP id g20-20020a056a0023d400b006be22db7a13mr13660453pfc.25.1698785928629; Tue, 31 Oct 2023 13:58:48 -0700 (PDT) Received: from fedora.. ([38.142.2.14]) by smtp.gmail.com with ESMTPSA id e8-20020a056a00162800b006b84ed9371esm60012pfc.177.2023.10.31.13.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 13:58:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: fengchengwen@huawei.com, Stephen Hemminger Subject: [RFC] kvargs: don't pass parse handler a NULL pointer Date: Tue, 31 Oct 2023 13:58:32 -0700 Message-ID: <20231031205844.91232-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230314124813.39521-1-fengchengwen@huawei.com> References: <20230314124813.39521-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org There is class of problems in current DPDK where rte_kvargs is used a key/value pair is passed without an associated value. Currently, this can cause a NULL dereference in the rte_kvargs_process handler. Reported-by: Chengwen Feng Signed-off-by: Stephen Hemminger --- lib/kvargs/rte_kvargs.c | 3 +++ lib/kvargs/rte_kvargs.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/kvargs/rte_kvargs.c b/lib/kvargs/rte_kvargs.c index c77bb82feb..5481f58584 100644 --- a/lib/kvargs/rte_kvargs.c +++ b/lib/kvargs/rte_kvargs.c @@ -185,6 +185,9 @@ rte_kvargs_process(const struct rte_kvargs *kvlist, for (i = 0; i < kvlist->count; i++) { pair = &kvlist->pairs[i]; if (key_match == NULL || strcmp(pair->key, key_match) == 0) { + if (pair->value == NULL) + return -1; + if ((*handler)(pair->key, pair->value, opaque_arg) < 0) return -1; } diff --git a/lib/kvargs/rte_kvargs.h b/lib/kvargs/rte_kvargs.h index 4900b750bc..fd9a3238f0 100644 --- a/lib/kvargs/rte_kvargs.h +++ b/lib/kvargs/rte_kvargs.h @@ -178,6 +178,9 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist, * handler function with the for a given arg_name passing the value on the * dictionary for that key and a given extra argument. * + * If no value was specified with the given key, then this + * function will return -1 and the handlere will not be called. + * * @param kvlist * The rte_kvargs structure. No error if NULL. * @param key_match -- 2.41.0