From: Vladimir Serbinenko <phcoder@gmail.com>
To: grub-devel@gnu.org
Cc: Vladimir Serbinenko <phcoder@gmail.com>
Subject: [PATCH v14 07/15] libgcrypt: Fix coverity warnings
Date: Mon, 7 Jul 2025 14:52:13 +0000 [thread overview]
Message-ID: <20250707145318.97596-8-phcoder@gmail.com> (raw)
In-Reply-To: <20250707145318.97596-1-phcoder@gmail.com>
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
.../libgcrypt-patches/03_mpiutil_alloc.patch | 20 ++++++++++
.../lib/libgcrypt-patches/03_sexp_free.patch | 37 +++++++++++++++++++
2 files changed, 57 insertions(+)
create mode 100644 grub-core/lib/libgcrypt-patches/03_mpiutil_alloc.patch
create mode 100644 grub-core/lib/libgcrypt-patches/03_sexp_free.patch
diff --git a/grub-core/lib/libgcrypt-patches/03_mpiutil_alloc.patch b/grub-core/lib/libgcrypt-patches/03_mpiutil_alloc.patch
new file mode 100644
index 000000000..7014f827d
--- /dev/null
+++ b/grub-core/lib/libgcrypt-patches/03_mpiutil_alloc.patch
@@ -0,0 +1,20 @@
+Fix NULL pointer dereference in case of failed alloc
+
+CID# 369001
+
+Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
+
+diff --git a/grub-core/lib/libgcrypt/mpi/mpiutil.c b/grub-core/lib/libgcrypt/mpi/mpiutil.c
+index 3a372374f..dc53db09d 100644
+--- a/grub-core/lib/libgcrypt-grub/mpi/mpiutil.c
++++ b/grub-core/lib/libgcrypt-grub/mpi/mpiutil.c
+@@ -432,6 +432,9 @@ _gcry_mpi_alloc_like( gcry_mpi_t a )
+ int n = (a->sign+7)/8;
+ void *p = _gcry_is_secure(a->d)? xtrymalloc_secure (n)
+ : xtrymalloc (n);
++ if ( !p ) {
++ _gcry_fatal_error (GPG_ERR_ENOMEM, NULL);
++ }
+ memcpy( p, a->d, n );
+ b = mpi_set_opaque( NULL, p, a->sign );
+ }
diff --git a/grub-core/lib/libgcrypt-patches/03_sexp_free.patch b/grub-core/lib/libgcrypt-patches/03_sexp_free.patch
new file mode 100644
index 000000000..33552ef54
--- /dev/null
+++ b/grub-core/lib/libgcrypt-patches/03_sexp_free.patch
@@ -0,0 +1,37 @@
+sexp: Add missing free on error path
+
+CID# 541475
+
+Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
+
+diff --git a/grub-core/lib/libgcrypt/src/sexp.c b/grub-core/lib/libgcrypt/src/sexp.c
+index d15f1a790..250559f75 100644
+--- a/grub-core/lib/libgcrypt-grub/src/sexp.c
++++ b/grub-core/lib/libgcrypt-grub/src/sexp.c
+@@ -1157,6 +1157,17 @@ do_vsexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
+ } \
+ } while (0)
+
++#define MAKE_SPACE_EXTRA_CLEANUP(n, cleanup) do { \
++ gpg_err_code_t _ms_err = make_space (&c, (n)); \
++ if (_ms_err) \
++ { \
++ err = _ms_err; \
++ *erroff = p - buffer; \
++ cleanup; \
++ goto leave; \
++ } \
++ } while (0)
++
+ /* The STORE_LEN macro is used to store the length N at buffer P. */
+ #define STORE_LEN(p,n) do { \
+ DATALEN ashort = (n); \
+@@ -1368,7 +1379,7 @@ do_vsexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
+ goto leave;
+ }
+
+- MAKE_SPACE (datalen);
++ MAKE_SPACE_EXTRA_CLEANUP (datalen, xfree (b64buf));
+ *c.pos++ = ST_DATA;
+ STORE_LEN (c.pos, datalen);
+ for (i = 0; i < datalen; i++)
--
2.49.0
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2025-07-07 15:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 14:52 [PATCH v14 00/15] Import libgcrypt 1.11 Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 01/15] " Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 02/15] Import b64dec from gpg-error Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 03/15] b64dec: Add harness for compilation in GRUB environment Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 04/15] Adjust import script, definitions and API users for libgcrypt 1.11 Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 05/15] Add DSA and RSA SEXP tests Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 06/15] keccak: Disable acceleration with SSE asm Vladimir Serbinenko
2025-07-07 14:52 ` Vladimir Serbinenko [this message]
2025-07-07 14:52 ` [PATCH v14 08/15] Remove now unneeded gcrypt compilation flag Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 09/15] gcry: Ignore sign-compare warnings Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 10/15] libgcrypt: Import blake family of hashes Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 11/15] import_gcry: Make compatible with python 3.4 Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 12/15] import_gcry: Fix pylint warnings Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 13/15] libgcrypt: Don't use 64-bit division on platforms where it's slow Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 14/15] libgcrypt: Fix a memory leak Vladimir Serbinenko
2025-07-07 14:52 ` [PATCH v14 15/15] Write how to import new libgcrypt Vladimir Serbinenko
2025-07-10 15:34 ` [PATCH v14 00/15] Import libgcrypt 1.11 Daniel Kiper
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250707145318.97596-8-phcoder@gmail.com \
--to=phcoder@gmail.com \
--cc=grub-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.