Make sure that some memory zeroing always happens.
authorWayne Davison <wayned@samba.org>
Tue, 8 Jan 2019 22:46:41 +0000 (14:46 -0800)
committerWayne Davison <wayned@samba.org>
Tue, 8 Jan 2019 22:46:41 +0000 (14:46 -0800)
authenticate.c
fileio.c
util.c

index eca5baf1bdf47816f60912a9b36746b3c7cf3583..8534a0b2f576c1ef853b9a3b54877493e03eb794 100644 (file)
@@ -162,8 +162,8 @@ static const char *check_secret(int module, const char *user, const char *group,
 
        fclose(fh);
 
-       memset(line, 0, sizeof line);
-       memset(pass2, 0, sizeof pass2);
+       force_memzero(line, sizeof line);
+       force_memzero(pass2, sizeof pass2);
 
        return err;
 }
@@ -318,8 +318,8 @@ char *auth_server(int f_in, int f_out, int module, const char *host,
                err = check_secret(module, line, group, challenge, pass);
        }
 
-       memset(challenge, 0, sizeof challenge);
-       memset(pass, 0, strlen(pass));
+       force_memzero(challenge, sizeof challenge);
+       force_memzero(pass, strlen(pass));
 
        if (auth_uid_groups) {
                int j;
index b183e200bdce6e8f703426f3b376d690102984fa..3f55e7089f1d83dda557c190d6e106441359d45e 100644 (file)
--- a/fileio.c
+++ b/fileio.c
@@ -322,7 +322,9 @@ int unmap_file(struct map_struct *map)
                map->p = NULL;
        }
        ret = map->status;
-       memset(map, 0, sizeof map[0]);
+#if 0 /* I don't think we really need this. */
+       force_memzero(map, sizeof map[0]);
+#endif
        free(map);
 
        return ret;
diff --git a/util.c b/util.c
index 72b3944ffe4b5eabca48b12d4f0e95382f2ce44b..fbbfd8babfd3cf64d0447000d8cd64c62b99849a 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1682,3 +1682,11 @@ void *expand_item_list(item_list *lp, size_t item_size,
        }
        return (char*)lp->items + (lp->count++ * item_size);
 }
+
+/* This zeroing of memory won't be optimized away by the compiler. */
+void force_memzero(void *buf, size_t len)
+{
+    volatile uchar *z = buf;
+    while (len-- > 0)
+       *z++ = '\0';
+}