read-file: use memset_explicit
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 28 Nov 2022 04:52:04 +0000 (20:52 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 29 Nov 2022 06:03:58 +0000 (22:03 -0800)
* 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
lib/read-file.c
modules/read-file

index 80f8d2c9cd88a0352bfd2b33d0cba0a80822a2c4..2d29d1f646c424563c74eff06307faa77492be8f 100644 (file)
--- 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:
index 7e02a4380efec5b0e8de1ee72918f366489f9eaf..c63aaf0db44c59e999e10ae7b9fe0378d282cf2e 100644 (file)
@@ -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;
index e087c3567e2bdd8fe92c20825c0eed6078b189a8..bdfdec8488ad298477f15f473c38c5de5ef5c2eb 100644 (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