bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Darren Kenny <darren.kenny@oracle.com>
To: bug-gnulib@gnu.org
Cc: darren.kenny@oracle.com
Subject: [PATCH 3/3] lib/regexec: Resolve unused variable
Date: Fri, 18 Jun 2021 15:44:23 +0000	[thread overview]
Message-ID: <3932753cd7929507688d341754fae944dac9a983.1624030621.git.darren.kenny@oracle.com> (raw)
In-Reply-To: <cover.1624030621.git.darren.kenny@oracle.com>

This is a fairly minor issue where a variable is being assigned to but
not checked before it is overwritten again.

The reason for this issue is that we are not building with DEBUG set and
this in turn means that the assert() that reads the value of the
variable match_last is being processed out.

The solution, move the assignment to match_last in to an ifdef DEBUG too.

This was originally found during a Coverity scan of GRUB2.

Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
---
 lib/regexec.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/regexec.c b/lib/regexec.c
index 2b2ab8e4afd0..ed3fa43bd0d1 100644
--- a/lib/regexec.c
+++ b/lib/regexec.c
@@ -816,7 +816,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length,
 		    break;
 		  if (__glibc_unlikely (err != REG_NOMATCH))
 		    goto free_return;
+#ifdef DEBUG
+		  /* Only used for assertion below when DEBUG is set, otherwise
+		     it will be over-written when we loop around.  */
 		  match_last = -1;
+#endif
 		}
 	      else
 		break; /* We found a match.  */
-- 
2.18.4



  parent reply	other threads:[~2021-06-18 16:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 15:44 [PATCH 0/3] Some Coverity fixes from GRUB Darren Kenny
2021-06-18 15:44 ` [PATCH 1/3] lib/regexec: Fix possible null-dereference Darren Kenny
2021-08-11  7:28   ` Paul Eggert
2021-08-23 10:05     ` Darren Kenny
2021-08-23 20:09       ` Paul Eggert
2021-08-24 15:11         ` Darren Kenny
2021-08-24 18:52           ` Paul Eggert
2021-06-18 15:44 ` [PATCH 2/3] lib/argp-help: Fix possible dereference of a NULL state Darren Kenny
2021-06-18 17:36   ` Bruno Haible
2021-06-21  9:32     ` Darren Kenny
2021-06-18 15:44 ` Darren Kenny [this message]
2021-08-11  7:24   ` [PATCH 3/3] lib/regexec: Resolve unused variable Paul Eggert
2021-08-23 10:38     ` Darren Kenny
2021-08-23 13:00       ` Bruno Haible
2021-08-23 21:04       ` Paul Eggert
2021-08-06 14:29 ` [PATCH 0/3] Some Coverity fixes from GRUB Darren Kenny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3932753cd7929507688d341754fae944dac9a983.1624030621.git.darren.kenny@oracle.com \
    --to=darren.kenny@oracle.com \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).