Message ID | 20241023100925.2381071-1-ant.v.moryakov@gmail.com |
---|---|
State | Dropped |
Delegated to: | Mark Wielaard |
Headers |
Return-Path: <elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 583443858C60 for <patchwork@sourceware.org>; Wed, 23 Oct 2024 10:09:57 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 6A271385840C for <elfutils-devel@sourceware.org>; Wed, 23 Oct 2024 10:09:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A271385840C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6A271385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729678187; cv=none; b=IPJ+IRDs4yASgX4oCONFbyAq6bGtL9sr9vATDYdLAO3krT0GOrBJsVzeHMLDLlSqLWgxdNoStoWmUM3u+7qd5iTw7nWBdcrLEo6uwZgmcZY9fG0sZ8I8b/bKWidlsdoXvOoGnIvLj7gFQctGs/9IwUTwIUIHTuPwSCbA9Tz6YUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729678187; c=relaxed/simple; bh=mNMOb2QMMqykrYeB6sWqIeBr1GrkltOWoaMRhIxFzOg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=YbnG3LFJcaYsGpHD6MPfzxqICEtZC/PpnOOf7+KpWxKFTUt2aTXzdcejISd/0GBvCqY9QA/ReXBGHYbceCFufR6WaM8HBOtH9riVysMJd+bnNP7Ldo1Qh0icnrrA6Kiq5h0cdtQU4bK93lvyCDx+ArmidUmuA1ntN8LBoPErzj8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-539fbbadf83so8748706e87.0 for <elfutils-devel@sourceware.org>; Wed, 23 Oct 2024 03:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729678182; x=1730282982; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7gM8apfOZ+H3i1cSFFfAB12yhWewlQNXZkVIAEUZaPs=; b=PA8Wp8i9kwh09JhHq3ytb66hC2bjSKNiY5rWOdBlJUxGoIj4JWpevCArOdOn6DLzVL zCnNE8peiapjQL/a4S5R9srLbW0nxg32UsJwVS9n/hMJI/lhflAxsS0qIo5liJtBdIVB mrc1OuNyrweV52RQt1ei7lfaTSm/5p/iSqXUCiaXYoyiZTZuZdW0IcJUzI3cW8ChY6bT l/h2Xe3wtQ4W+mYukDXEZqwQa38sYzYJ+qShHHC0b7jpu2RQ9QcMOtRFaEu9W++ZTLva XqqXsc+UhIBAaW43BDAFxSLiM04oXrx+2glVjmxco6yqvQXtJG2REgWc60R64CODKzbg GfWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729678182; x=1730282982; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7gM8apfOZ+H3i1cSFFfAB12yhWewlQNXZkVIAEUZaPs=; b=m9K0QkpII4Kz/xyz+fXStAwTCbSoa9YpuXkIay3m4HOLLDm1322fPJT0nMiwyQvZcl PazmwVmKo2gAfgD6yroZWbb9gkVsAjCw5FsLcOG+2zYpz39Cy8qFDLGxHWrO3EjQsWW4 MFsszhWhs1Qb0AWd1MfGu3amslhiVBrQTXp6O6rM0rS2rs7vL1BKONI9XYFANGbso6yP 2R9Mcb86KCNjsCR2WicxhROes9a1NdWSW3KKBVV6C4P6FpXMyuklCAP0xHY5EwHM+c+X wGziqJ6KSTWX/0vcpkwE+TyaTl4Lvk+lzVwgAp6WZl0gvRBRC7BtN/M1INNE5IrdnbSg 4xqQ== X-Gm-Message-State: AOJu0Yyfi1t9Tuo5mTKzm9+IcTVXsySxUnxAnNmUC0yuAAvDMw84ZuA0 IXh/+VYApkCCBrSFTDh02nlq7mfn64GD5DTEhkgEoLTz0UifcHgx7+Vpn2HS1S0= X-Google-Smtp-Source: AGHT+IHokeTC0iDUnSwFlC6VtAW1c0aZKhbPb/DTMyx4uO4EUBoqQTcbfDX1657+AZmi1g2Dta802g== X-Received: by 2002:a05:6512:1154:b0:53a:a26:5690 with SMTP id 2adb3069b0e04-53b1a341e0bmr943911e87.34.1729678182189; Wed, 23 Oct 2024 03:09:42 -0700 (PDT) Received: from anton-desktop.. (static.38.52.108.65.clients.your-server.de. [65.108.52.38]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53a22431977sm1010472e87.197.2024.10.23.03.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 03:09:40 -0700 (PDT) From: ant.v.moryakov@gmail.com To: elfutils-devel@sourceware.org Cc: AntonMoryakov <ant.v.moryakov@gmail.com> Subject: [PATCH] elfint.c: Fix NULL pointer dereference issue in process_file function Date: Wed, 23 Oct 2024 13:09:25 +0300 Message-Id: <20241023100925.2381071-1-ant.v.moryakov@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list <elfutils-devel.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/elfutils-devel/> List-Post: <mailto:elfutils-devel@sourceware.org> List-Help: <mailto:elfutils-devel-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=subscribe> Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org |
Series |
elfint.c: Fix NULL pointer dereference issue in process_file function
|
|
Commit Message
Anton Moryakov
Oct. 23, 2024, 10:09 a.m. UTC
From: AntonMoryakov <ant.v.moryakov@gmail.com>
fix: fixed null pointer inference error in process_file function
Fixed a bug that could cause the program to crash when processing files without a suffix.
Added a NULL check for the suffix pointer before calling stpcpy().
---
src/elflint.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Comments
Hi Anton, On Wed, 2024-10-23 at 13:09 +0300, ant.v.moryakov@gmail.com wrote: > From: AntonMoryakov <ant.v.moryakov@gmail.com> > > fix: fixed null pointer inference error in process_file function > > Fixed a bug that could cause the program to crash when processing files without a suffix. Do you have a testcase for this? > Added a NULL check for the suffix pointer before calling stpcpy(). See comments below about where to put this check and the formatting. Please also see the CONTRIBUTING file for how to submit patches for inclusion. In particular the section "Sign your work" https://sourceware.org/cgit/elfutils/tree/CONTRIBUTING > --- > src/elflint.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/src/elflint.c b/src/elflint.c > index cdc6108d..14346045 100644 > --- a/src/elflint.c > +++ b/src/elflint.c > @@ -257,7 +257,12 @@ process_file (int fd, Elf *elf, const char *prefix, const char *suffix, > { > cp = mempcpy (cp, prefix, prefix_len); > *cp++ = '('; > - strcpy (stpcpy (new_suffix, suffix), ")"); > + if(suffix != NULL){ Could this check go with the if statement just before this code? > /* Create the full name of the file. */ > if (prefix != NULL) So that it reads if (prefix != NULL && suffix != NULL) > + strcpy (stpcpy (new_suffix, suffix), ")"); > + } > + else{ > + new_suffix[0] = '\0'; > + } > } > else > new_suffix[0] = '\0'; Note that the code formatting/indenting seems a little off. In general the elfutils code follows the GNU coding standard Formatting: https://www.gnu.org/prep/standards/standards.html#Formatting Thanks, Mark
diff --git a/src/elflint.c b/src/elflint.c index cdc6108d..14346045 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -257,7 +257,12 @@ process_file (int fd, Elf *elf, const char *prefix, const char *suffix, { cp = mempcpy (cp, prefix, prefix_len); *cp++ = '('; - strcpy (stpcpy (new_suffix, suffix), ")"); + if(suffix != NULL){ + strcpy (stpcpy (new_suffix, suffix), ")"); + } + else{ + new_suffix[0] = '\0'; + } } else new_suffix[0] = '\0';