All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Serbinenko <phcoder@gmail.com>
To: grub-devel@gnu.org
Cc: Vladimir Serbinenko <phcoder@gmail.com>
Subject: [PATCH v8 3/9] b64dec: Adjust for compilation in GRUB environment
Date: Fri,  4 Apr 2025 02:05:05 +0300	[thread overview]
Message-ID: <20250403230630.3572282-4-phcoder@gmail.com> (raw)
In-Reply-To: <20250403230630.3572282-1-phcoder@gmail.com>

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
 grub-core/lib/b64dec.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/grub-core/lib/b64dec.c b/grub-core/lib/b64dec.c
index 868d98568..8aafa9700 100644
--- a/grub-core/lib/b64dec.c
+++ b/grub-core/lib/b64dec.c
@@ -26,7 +26,21 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "gpgrt-int.h"
+#include <grub/crypto.h>
+
+struct _gpgrt_b64state
+{
+  int idx;
+  int quad_count;
+  char *title;
+  unsigned char radbuf[4];
+  unsigned int crc;
+  gpg_err_code_t lasterr;
+  unsigned int flags;
+  unsigned int stop_seen:1;
+  unsigned int invalid_encoding:1;
+  unsigned int using_decoder:1;
+};
 
 
 /* The reverse base-64 list used for base-64 decoding. */
@@ -64,22 +78,22 @@ enum decoder_states
    string the decoder will skip everything until a "-----BEGIN " line
    has been seen, decoding ends at a "----END " line.  */
 gpgrt_b64state_t
-_gpgrt_b64dec_start (const char *title)
+gpgrt_b64dec_start (const char *title)
 {
   gpgrt_b64state_t state;
   char *t = NULL;
 
   if (title)
     {
-      t = xtrystrdup (title);
+      t = grub_strdup (title);
       if (!t)
         return NULL;
     }
 
-  state = xtrycalloc (1, sizeof (struct _gpgrt_b64state));
+  state = grub_calloc (1, sizeof (struct _gpgrt_b64state));
   if (!state)
     {
-      xfree (t);
+      grub_free (t);
       return NULL;
     }
 
@@ -100,7 +114,7 @@ _gpgrt_b64dec_start (const char *title)
 /* Do in-place decoding of base-64 data of LENGTH in BUFFER.  Stores the
    new length of the buffer at R_NBYTES. */
 gpg_err_code_t
-_gpgrt_b64dec_proc (gpgrt_b64state_t state, void *buffer, size_t length,
+gpgrt_b64dec_proc (gpgrt_b64state_t state, void *buffer, size_t length,
                     size_t *r_nbytes)
 {
   enum decoder_states ds = state->idx;
@@ -115,7 +129,7 @@ _gpgrt_b64dec_proc (gpgrt_b64state_t state, void *buffer, size_t length,
     {
       *r_nbytes = 0;
       state->lasterr = GPG_ERR_EOF;
-      xfree (state->title);
+      grub_free (state->title);
       state->title = NULL;
       return state->lasterr;
     }
@@ -241,7 +255,7 @@ _gpgrt_b64dec_proc (gpgrt_b64state_t state, void *buffer, size_t length,
             state->stop_seen = 1;
           break;
         default:
-          gpgrt_assert (!"invalid state");
+          grub_fatal ("invalid state");
         }
     }
 
@@ -257,7 +271,7 @@ _gpgrt_b64dec_proc (gpgrt_b64state_t state, void *buffer, size_t length,
 /* Return an error code in case an encoding error has been found
    during decoding. */
 gpg_err_code_t
-_gpgrt_b64dec_finish (gpgrt_b64state_t state)
+gpgrt_b64dec_finish (gpgrt_b64state_t state)
 {
   gpg_error_t err;
 
@@ -270,10 +284,10 @@ _gpgrt_b64dec_finish (gpgrt_b64state_t state)
     err = state->lasterr;
   else
     {
-      xfree (state->title);
+      grub_free (state->title);
       err = state->invalid_encoding? GPG_ERR_BAD_DATA : 0;
     }
-  xfree (state);
+  grub_free (state);
 
   return err;
 }
-- 
2.49.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  parent reply	other threads:[~2025-04-03 23:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 23:05 [PATCH v8 0/9] Update libgcrypt to 1.11 Vladimir Serbinenko
2025-04-03 23:05 ` [PATCH v8 1/9] Import libgcrypt 1.11 Vladimir Serbinenko
2025-04-03 23:05 ` [PATCH v8 2/9] Import b64dec from gpg-error Vladimir Serbinenko
2025-04-03 23:05 ` Vladimir Serbinenko [this message]
2025-04-03 23:05 ` [PATCH v8 4/9] Adjust import script, definitions and API users for libgcrypt 1.11 Vladimir Serbinenko
2025-04-03 23:05 ` [PATCH v8 5/9] Add DSA and RSA SEXP tests Vladimir Serbinenko
2025-04-03 23:05 ` [PATCH v8 6/9] keccak: Disable acceleration with SSE asm Vladimir Serbinenko
2025-04-03 23:05 ` [PATCH v8 7/9] libgcrypt: Fix coverity warnings Vladimir Serbinenko
2025-04-03 23:05 ` [PATCH v8 8/9] Remove now unneeded gcrypt compilation flag Vladimir Serbinenko
2025-04-03 23:05 ` [PATCH v8 9/9] Implement __aeabi_uldivmod Vladimir Serbinenko
2025-04-07 19:14 ` [PATCH v8 0/9] Update libgcrypt to 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=20250403230630.3572282-4-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.