bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PROPOSED 2/4] read-file: use memset_explicit
Date: Sun, 27 Nov 2022 20:55:41 -0800	[thread overview]
Message-ID: <20221128045543.1355731-3-eggert@cs.ucla.edu> (raw)
In-Reply-To: <20221128045543.1355731-1-eggert@cs.ucla.edu>

* lib/read-file.c (fread_file, read_file):
Use memset_explicit instead of explicit_bzero.
* modules/read-file (Depends-on): Depend on memset_explicit
instead of on explicit_bzero.
---
 ChangeLog         |  6 ++++++
 lib/read-file.c   | 12 ++++++------
 modules/read-file |  2 +-
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 80f8d2c9cd..2d29d1f646 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2022-11-27  Paul Eggert  <eggert@cs.ucla.edu>
 
+	read-file: use memset_explicit
+	* lib/read-file.c (fread_file, read_file):
+	Use memset_explicit instead of explicit_bzero.
+	* modules/read-file (Depends-on): Depend on memset_explicit
+	instead of on explicit_bzero.
+
 	memset_explicit: new module
 	* doc/posix-functions/memset_explicit.texi, lib/memset_explicit.c:
 	* m4/memset_explicit.m4, modules/memset_explicit:
diff --git a/lib/read-file.c b/lib/read-file.c
index 7e02a4380e..c63aaf0db4 100644
--- a/lib/read-file.c
+++ b/lib/read-file.c
@@ -31,7 +31,7 @@
 /* Get malloc, realloc, free. */
 #include <stdlib.h>
 
-/* Get explicit_bzero, memcpy. */
+/* Get memcpy, memset_explicit. */
 #include <string.h>
 
 /* Get errno. */
@@ -107,11 +107,11 @@ fread_file (FILE *stream, int flags, size_t *length)
                   {
                     char *smaller_buf = malloc (size + 1);
                     if (smaller_buf == NULL)
-                      explicit_bzero (buf + size, alloc - size);
+                      memset_explicit (buf + size, 0, alloc - size);
                     else
                       {
                         memcpy (smaller_buf, buf, size);
-                        explicit_bzero (buf, alloc);
+                        memset_explicit (buf, 0, alloc);
                         free (buf);
                         buf = smaller_buf;
                       }
@@ -154,7 +154,7 @@ fread_file (FILE *stream, int flags, size_t *length)
                   break;
                 }
               memcpy (new_buf, buf, save_alloc);
-              explicit_bzero (buf, save_alloc);
+              memset_explicit (buf, 0, save_alloc);
               free (buf);
             }
           else if (!(new_buf = realloc (buf, alloc)))
@@ -168,7 +168,7 @@ fread_file (FILE *stream, int flags, size_t *length)
       }
 
     if (flags & RF_SENSITIVE)
-      explicit_bzero (buf, alloc);
+      memset_explicit (buf, 0, alloc);
 
     free (buf);
     errno = save_errno;
@@ -206,7 +206,7 @@ read_file (const char *filename, int flags, size_t *length)
       if (out)
         {
           if (flags & RF_SENSITIVE)
-            explicit_bzero (out, *length);
+            memset_explicit (out, 0, *length);
           free (out);
         }
       return NULL;
diff --git a/modules/read-file b/modules/read-file
index e087c3567e..bdfdec8488 100644
--- a/modules/read-file
+++ b/modules/read-file
@@ -7,12 +7,12 @@ lib/read-file.c
 m4/read-file.m4
 
 Depends-on:
-explicit_bzero
 fopen-gnu
 free-posix
 fstat
 ftello
 malloc-posix
+memset_explicit
 realloc-posix
 stdint
 sys_stat
-- 
2.37.2



  parent reply	other threads:[~2022-11-28  4:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28  4:55 [PROPOSED 0/4] memset_explicit patches Paul Eggert
2022-11-28  4:55 ` [PROPOSED 1/4] memset_explicit: new module Paul Eggert
2022-11-28 16:17   ` Bruno Haible
2022-11-28  4:55 ` Paul Eggert [this message]
2022-11-28  4:55 ` [PROPOSED 3/4] explicit_bzero: memset_explicit is standard Paul Eggert
2022-11-28  4:55 ` [PROPOSED 4/4] explicit_bzero: implement via memset_explicit Paul Eggert
2022-11-28 16:17   ` Bruno Haible
2022-11-29  6:06     ` Paul Eggert
2022-11-29  8:09       ` Bruno Haible
2022-11-28 10:15 ` [PROPOSED 0/4] memset_explicit patches Simon Josefsson via Gnulib discussion list
2022-11-28 16:04   ` Bruno Haible

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=20221128045543.1355731-3-eggert@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --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).