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 3DEE5A034D; Wed, 9 Feb 2022 21:41:58 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 04FCD41101; Wed, 9 Feb 2022 21:41:58 +0100 (CET) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id E701940140 for ; Wed, 9 Feb 2022 21:41:56 +0100 (CET) Received: by mail-pl1-f174.google.com with SMTP id x4so3332607plb.4 for ; Wed, 09 Feb 2022 12:41:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ac1AUV/dmemLRyHe3poIesh4maNvfL0+E/Uyg7hbkdQ=; b=AilENhlnx5nQHnjw3roY9EW/wgqFK5M4yTXRmoFCw4IDp5jKdWjw/gYt8pPUxknkhy ajs2zr4KXgO3eUxWEVJuXdLVEVgrFMTluZ5Z+TCf28tvjYWNNFcRo5RDVh5nRiMwSt12 m2H2CTSk1MO02h5gr8vzNK+y+iNI5oBppJTm5fbf8gAuNeNI8Y76nfa4gE4OuPma6CP1 oAVWchnRunuXrsilKT2GiuuUZONrtM3FOpmq6vltF+Qr+O6d5Oz3TzdclQMGGDUSqYP3 zGDessSwpgXsoUI08WZTRVxSu5Oic/+5xoaNtLOwG2CWLRFyFCRZ8ScGvbsgSBkNHQs/ WP9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ac1AUV/dmemLRyHe3poIesh4maNvfL0+E/Uyg7hbkdQ=; b=2o2+c0DtTWK1+FuU1+NRBjOUYoNUXoysNqf9lDCqVT7jPlpxnGSPaJi+aNfq5XmxUg ou8iEuDZwg2KKKO8EH86YPH73QbvazKm0Ipqo5Xb14bOPnPDiCpwWQJThJoiDFPCKPAb TLud1kX8ISBR3o5We2vg6HqysA4CxktIz+p94kAZniQBK0YUeYCtNRQkgSry06IQs5P7 ocgNUipj5ybrN8I8I/K9TzSpfkcuhnLICNMKJOKI1b9VQoSzGw2P34H58tx3Gc3X/EQX 1ShcMkVx+ngTuictxhTgmArgBppm1cmYM7zoe/jtX082z9/QhJZA9jjOI8lgE1aQTKbr TxMg== X-Gm-Message-State: AOAM531KlXAKtRqzFm6n7bkB5DWU9b6Ssw5C/UqgMJ+FXF9Gg4tjaK81 hyC/3UO43KUFN7uD1EZREzwzW3ELABCuAQEegDg= X-Google-Smtp-Source: ABdhPJz86H1X/ht1eJp7W27UHQlltcQiWgeeUFchXRPqNe3w2QZsuIcN8UUsAqGRH5r/OC0TetvLwQ== X-Received: by 2002:a17:902:8c87:: with SMTP id t7mr3939041plo.170.1644439315707; Wed, 09 Feb 2022 12:41:55 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id z14sm14897519pfh.173.2022.02.09.12.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 12:41:55 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Stephen Hemminger Subject: [PATCH v3] eal: simplify argv[0] handling Date: Wed, 9 Feb 2022 12:41:51 -0800 Message-Id: <20220209204151.443418-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220202194738.404876-1-stephen@networkplumber.org> References: <20220202194738.404876-1-stephen@networkplumber.org> 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 The rte_eal_init function looks at argv[0] to determine the program name to pass to the log init function. But in corner cases argv[0] maybe NULL leading to a SEGV. The code here is just using argv[0] to generate logid which does not have to be in a static string, openlog() will handle a const char pointer. Simple workaround for argv[0] being NULL is to pass NULL to openlog() and let it handle it. Both glibc, and musl handle this case. Signed-off-by: Stephen Hemminger --- v3 - redo to make this limited to just the null argv[0] bug lib/eal/linux/eal.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 9c8395ab14d0..c0ff325c4ce9 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -966,8 +966,7 @@ rte_eal_init(int argc, char **argv) pthread_t thread_id; static uint32_t run_once; uint32_t has_run = 0; - const char *p; - static char logid[PATH_MAX]; + const char *logid = NULL; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_MAX_THREAD_NAME_LEN]; bool phys_addrs; @@ -989,8 +988,12 @@ rte_eal_init(int argc, char **argv) return -1; } - p = strrchr(argv[0], '/'); - strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid)); + if (argv && argv[0]) { + const char *p = strrchr(argv[0], '/'); + + logid = p ? p + 1 : argv[0]; + } + thread_id = pthread_self(); eal_reset_internal_config(internal_conf); -- 2.34.1