diff options
| author | Paul Eggert | 2021-10-05 09:08:02 -0700 |
|---|---|---|
| committer | Paul Eggert | 2021-10-05 09:09:23 -0700 |
| commit | 4d76765b6c8a3117c436ccc93572cddfd8d17d7c (patch) | |
| tree | f78c3f96695f5af738e67b2d08a87b27337d2d41 | |
| parent | 18308b739a561bff677929da2a1412e91c0d05cd (diff) | |
| download | emacs-4d76765b6c8a3117c436ccc93572cddfd8d17d7c.tar.gz emacs-4d76765b6c8a3117c436ccc93572cddfd8d17d7c.zip | |
Fix md5 issue in recent Gnulib merge
When configured --with-native-compilation, Emacs needs md5_stream.
Problem reported by Andy Moreton (Bug#50985#23).
* admin/merge-gnulib (GNULIB_MODULES): Add crypto/md5,
needed for --with-native-compilation.
(AVOIDED_MODULES): Avoid crypto/af_alg, since Emacs doesn’t
need to bother with kernel-supported cryptography algorithms.
* lib/gnulib.mk.in, m4/gnulib-comp.m4:
Regenerate by running admin/merge-gnulib.
* lib/md5-stream.c: New file, copied from Gnulib.
| -rwxr-xr-x | admin/merge-gnulib | 5 | ||||
| -rw-r--r-- | lib/gnulib.mk.in | 12 | ||||
| -rw-r--r-- | lib/md5-stream.c | 141 | ||||
| -rw-r--r-- | m4/gnulib-comp.m4 | 2 |
4 files changed, 157 insertions, 3 deletions
diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 10cc73aa734..886f37e28cc 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib | |||
| @@ -30,7 +30,8 @@ GNULIB_MODULES=' | |||
| 30 | canonicalize-lgpl | 30 | canonicalize-lgpl |
| 31 | careadlinkat close-stream copy-file-range | 31 | careadlinkat close-stream copy-file-range |
| 32 | count-leading-zeros count-one-bits count-trailing-zeros | 32 | count-leading-zeros count-one-bits count-trailing-zeros |
| 33 | crypto/md5-buffer crypto/sha1-buffer crypto/sha256-buffer crypto/sha512-buffer | 33 | crypto/md5 crypto/md5-buffer |
| 34 | crypto/sha1-buffer crypto/sha256-buffer crypto/sha512-buffer | ||
| 34 | d-type diffseq double-slash-root dtoastr dtotimespec dup2 | 35 | d-type diffseq double-slash-root dtoastr dtotimespec dup2 |
| 35 | environ execinfo explicit_bzero faccessat | 36 | environ execinfo explicit_bzero faccessat |
| 36 | fchmodat fcntl fcntl-h fdopendir file-has-acl | 37 | fchmodat fcntl fcntl-h fdopendir file-has-acl |
| @@ -49,7 +50,7 @@ GNULIB_MODULES=' | |||
| 49 | ' | 50 | ' |
| 50 | 51 | ||
| 51 | AVOIDED_MODULES=' | 52 | AVOIDED_MODULES=' |
| 52 | btowc close dup fchdir fstat langinfo lock | 53 | btowc close crypto/af_alg dup fchdir fstat langinfo lock |
| 53 | mbrtowc mbsinit memchr mkdir msvc-inval msvc-nothrow nl_langinfo | 54 | mbrtowc mbsinit memchr mkdir msvc-inval msvc-nothrow nl_langinfo |
| 54 | openat-die opendir pthread-h raise | 55 | openat-die opendir pthread-h raise |
| 55 | save-cwd select setenv sigprocmask stat stdarg stdbool | 56 | save-cwd select setenv sigprocmask stat stdarg stdbool |
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index bac27f3a68d..e9a1a5dc028 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | # --no-vc-files \ | 36 | # --no-vc-files \ |
| 37 | # --avoid=btowc \ | 37 | # --avoid=btowc \ |
| 38 | # --avoid=close \ | 38 | # --avoid=close \ |
| 39 | # --avoid=crypto/af_alg \ | ||
| 39 | # --avoid=dup \ | 40 | # --avoid=dup \ |
| 40 | # --avoid=fchdir \ | 41 | # --avoid=fchdir \ |
| 41 | # --avoid=fstat \ | 42 | # --avoid=fstat \ |
| @@ -79,6 +80,7 @@ | |||
| 79 | # count-leading-zeros \ | 80 | # count-leading-zeros \ |
| 80 | # count-one-bits \ | 81 | # count-one-bits \ |
| 81 | # count-trailing-zeros \ | 82 | # count-trailing-zeros \ |
| 83 | # crypto/md5 \ | ||
| 82 | # crypto/md5-buffer \ | 84 | # crypto/md5-buffer \ |
| 83 | # crypto/sha1-buffer \ | 85 | # crypto/sha1-buffer \ |
| 84 | # crypto/sha256-buffer \ | 86 | # crypto/sha256-buffer \ |
| @@ -544,8 +546,8 @@ GL_GNULIB_WRITE = @GL_GNULIB_WRITE@ | |||
| 544 | GL_GNULIB__EXIT = @GL_GNULIB__EXIT@ | 546 | GL_GNULIB__EXIT = @GL_GNULIB__EXIT@ |
| 545 | GMALLOC_OBJ = @GMALLOC_OBJ@ | 547 | GMALLOC_OBJ = @GMALLOC_OBJ@ |
| 546 | GMP_H = @GMP_H@ | 548 | GMP_H = @GMP_H@ |
| 547 | GNULIB_GETTIMEOFDAY = @GNULIB_GETTIMEOFDAY@ | ||
| 548 | GNULIBHEADERS_OVERRIDE_WINT_T = @GNULIBHEADERS_OVERRIDE_WINT_T@ | 549 | GNULIBHEADERS_OVERRIDE_WINT_T = @GNULIBHEADERS_OVERRIDE_WINT_T@ |
| 550 | GNULIB_GETTIMEOFDAY = @GNULIB_GETTIMEOFDAY@ | ||
| 549 | GNULIB_WARN_CFLAGS = @GNULIB_WARN_CFLAGS@ | 551 | GNULIB_WARN_CFLAGS = @GNULIB_WARN_CFLAGS@ |
| 550 | GNUSTEP_CFLAGS = @GNUSTEP_CFLAGS@ | 552 | GNUSTEP_CFLAGS = @GNUSTEP_CFLAGS@ |
| 551 | GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@ | 553 | GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@ |
| @@ -1473,6 +1475,14 @@ EXTRA_DIST += count-trailing-zeros.h | |||
| 1473 | endif | 1475 | endif |
| 1474 | ## end gnulib module count-trailing-zeros | 1476 | ## end gnulib module count-trailing-zeros |
| 1475 | 1477 | ||
| 1478 | ## begin gnulib module crypto/md5 | ||
| 1479 | ifeq (,$(OMIT_GNULIB_MODULE_crypto/md5)) | ||
| 1480 | |||
| 1481 | libgnu_a_SOURCES += md5-stream.c | ||
| 1482 | |||
| 1483 | endif | ||
| 1484 | ## end gnulib module crypto/md5 | ||
| 1485 | |||
| 1476 | ## begin gnulib module crypto/md5-buffer | 1486 | ## begin gnulib module crypto/md5-buffer |
| 1477 | ifeq (,$(OMIT_GNULIB_MODULE_crypto/md5-buffer)) | 1487 | ifeq (,$(OMIT_GNULIB_MODULE_crypto/md5-buffer)) |
| 1478 | 1488 | ||
diff --git a/lib/md5-stream.c b/lib/md5-stream.c new file mode 100644 index 00000000000..fb483b73347 --- /dev/null +++ b/lib/md5-stream.c | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | /* Functions to compute MD5 message digest of files or memory blocks. | ||
| 2 | according to the definition of MD5 in RFC 1321 from April 1992. | ||
| 3 | Copyright (C) 1995-1997, 1999-2001, 2005-2006, 2008-2021 Free Software | ||
| 4 | Foundation, Inc. | ||
| 5 | This file is part of the GNU C Library. | ||
| 6 | |||
| 7 | This file is free software: you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU Lesser General Public License as | ||
| 9 | published by the Free Software Foundation; either version 2.1 of the | ||
| 10 | License, or (at your option) any later version. | ||
| 11 | |||
| 12 | This file is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU Lesser General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU Lesser General Public License | ||
| 18 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | /* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. */ | ||
| 21 | |||
| 22 | #include <config.h> | ||
| 23 | |||
| 24 | /* Specification. */ | ||
| 25 | #if HAVE_OPENSSL_MD5 | ||
| 26 | # define GL_OPENSSL_INLINE _GL_EXTERN_INLINE | ||
| 27 | #endif | ||
| 28 | #include "md5.h" | ||
| 29 | |||
| 30 | #include <stdlib.h> | ||
| 31 | |||
| 32 | #if USE_UNLOCKED_IO | ||
| 33 | # include "unlocked-io.h" | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #include "af_alg.h" | ||
| 37 | |||
| 38 | #ifdef _LIBC | ||
| 39 | # include <endian.h> | ||
| 40 | # if __BYTE_ORDER == __BIG_ENDIAN | ||
| 41 | # define WORDS_BIGENDIAN 1 | ||
| 42 | # endif | ||
| 43 | /* We need to keep the namespace clean so define the MD5 function | ||
| 44 | protected using leading __ . */ | ||
| 45 | # define md5_init_ctx __md5_init_ctx | ||
| 46 | # define md5_process_block __md5_process_block | ||
| 47 | # define md5_process_bytes __md5_process_bytes | ||
| 48 | # define md5_finish_ctx __md5_finish_ctx | ||
| 49 | # define md5_stream __md5_stream | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #define BLOCKSIZE 32768 | ||
| 53 | #if BLOCKSIZE % 64 != 0 | ||
| 54 | # error "invalid BLOCKSIZE" | ||
| 55 | #endif | ||
| 56 | |||
| 57 | /* Compute MD5 message digest for bytes read from STREAM. The | ||
| 58 | resulting message digest number will be written into the 16 bytes | ||
| 59 | beginning at RESBLOCK. */ | ||
| 60 | int | ||
| 61 | md5_stream (FILE *stream, void *resblock) | ||
| 62 | { | ||
| 63 | switch (afalg_stream (stream, "md5", resblock, MD5_DIGEST_SIZE)) | ||
| 64 | { | ||
| 65 | case 0: return 0; | ||
| 66 | case -EIO: return 1; | ||
| 67 | } | ||
| 68 | |||
| 69 | char *buffer = malloc (BLOCKSIZE + 72); | ||
| 70 | if (!buffer) | ||
| 71 | return 1; | ||
| 72 | |||
| 73 | struct md5_ctx ctx; | ||
| 74 | md5_init_ctx (&ctx); | ||
| 75 | size_t sum; | ||
| 76 | |||
| 77 | /* Iterate over full file contents. */ | ||
| 78 | while (1) | ||
| 79 | { | ||
| 80 | /* We read the file in blocks of BLOCKSIZE bytes. One call of the | ||
| 81 | computation function processes the whole buffer so that with the | ||
| 82 | next round of the loop another block can be read. */ | ||
| 83 | size_t n; | ||
| 84 | sum = 0; | ||
| 85 | |||
| 86 | /* Read block. Take care for partial reads. */ | ||
| 87 | while (1) | ||
| 88 | { | ||
| 89 | /* Either process a partial fread() from this loop, | ||
| 90 | or the fread() in afalg_stream may have gotten EOF. | ||
| 91 | We need to avoid a subsequent fread() as EOF may | ||
| 92 | not be sticky. For details of such systems, see: | ||
| 93 | https://sourceware.org/bugzilla/show_bug.cgi?id=1190 */ | ||
| 94 | if (feof (stream)) | ||
| 95 | goto process_partial_block; | ||
| 96 | |||
| 97 | n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); | ||
| 98 | |||
| 99 | sum += n; | ||
| 100 | |||
| 101 | if (sum == BLOCKSIZE) | ||
| 102 | break; | ||
| 103 | |||
| 104 | if (n == 0) | ||
| 105 | { | ||
| 106 | /* Check for the error flag IFF N == 0, so that we don't | ||
| 107 | exit the loop after a partial read due to e.g., EAGAIN | ||
| 108 | or EWOULDBLOCK. */ | ||
| 109 | if (ferror (stream)) | ||
| 110 | { | ||
| 111 | free (buffer); | ||
| 112 | return 1; | ||
| 113 | } | ||
| 114 | goto process_partial_block; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | /* Process buffer with BLOCKSIZE bytes. Note that | ||
| 119 | BLOCKSIZE % 64 == 0 | ||
| 120 | */ | ||
| 121 | md5_process_block (buffer, BLOCKSIZE, &ctx); | ||
| 122 | } | ||
| 123 | |||
| 124 | process_partial_block: | ||
| 125 | |||
| 126 | /* Process any remaining bytes. */ | ||
| 127 | if (sum > 0) | ||
| 128 | md5_process_bytes (buffer, sum, &ctx); | ||
| 129 | |||
| 130 | /* Construct result in desired memory. */ | ||
| 131 | md5_finish_ctx (&ctx, resblock); | ||
| 132 | free (buffer); | ||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | /* | ||
| 137 | * Hey Emacs! | ||
| 138 | * Local Variables: | ||
| 139 | * coding: utf-8 | ||
| 140 | * End: | ||
| 141 | */ | ||
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index dd5bde8d797..a795fe76518 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 | |||
| @@ -63,6 +63,7 @@ AC_DEFUN([gl_EARLY], | |||
| 63 | # Code from module count-leading-zeros: | 63 | # Code from module count-leading-zeros: |
| 64 | # Code from module count-one-bits: | 64 | # Code from module count-one-bits: |
| 65 | # Code from module count-trailing-zeros: | 65 | # Code from module count-trailing-zeros: |
| 66 | # Code from module crypto/md5: | ||
| 66 | # Code from module crypto/md5-buffer: | 67 | # Code from module crypto/md5-buffer: |
| 67 | # Code from module crypto/sha1-buffer: | 68 | # Code from module crypto/sha1-buffer: |
| 68 | # Code from module crypto/sha256-buffer: | 69 | # Code from module crypto/sha256-buffer: |
| @@ -1207,6 +1208,7 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 1207 | lib/malloc/scratch_buffer_grow.c | 1208 | lib/malloc/scratch_buffer_grow.c |
| 1208 | lib/malloc/scratch_buffer_grow_preserve.c | 1209 | lib/malloc/scratch_buffer_grow_preserve.c |
| 1209 | lib/malloc/scratch_buffer_set_array_size.c | 1210 | lib/malloc/scratch_buffer_set_array_size.c |
| 1211 | lib/md5-stream.c | ||
| 1210 | lib/md5.c | 1212 | lib/md5.c |
| 1211 | lib/md5.h | 1213 | lib/md5.h |
| 1212 | lib/memmem.c | 1214 | lib/memmem.c |