File ImageMagick-CVE-2021-20313.patch of Package ImageMagick.30956
Index: ImageMagick-6.8.8-1/magick/memory.c
===================================================================
--- ImageMagick-6.8.8-1.orig/magick/memory.c 2021-04-15 14:29:38.738151576 +0200
+++ ImageMagick-6.8.8-1/magick/memory.c 2021-04-15 14:29:40.026158839 +0200
@@ -1062,25 +1062,36 @@ MagickExport MemoryInfo *RelinquishVirtu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ResetMagickMemory() fills the first size bytes of the memory area pointed to
-% by memory with the constant byte c.
+% by memory with the constant byte c. We use a volatile pointer when
+% updating the byte string. Most compilers will avoid optimizing away access
+% to a volatile pointer, even if the pointer appears to be unused after the
+% call.
%
% The format of the ResetMagickMemory method is:
%
-% void *ResetMagickMemory(void *memory,int byte,const size_t size)
+% void *ResetMagickMemory(void *memory,int c,const size_t size)
%
% A description of each parameter follows:
%
% o memory: a pointer to a memory allocation.
%
-% o byte: set the memory to this value.
+% o c: set the memory to this value.
%
% o size: size of the memory to reset.
%
*/
-MagickExport void *ResetMagickMemory(void *memory,int byte,const size_t size)
+MagickExport void *ResetMagickMemory(void *memory,int c,const size_t size)
{
+ volatile unsigned char
+ *p = memory;
+
+ size_t
+ n = size;
+
assert(memory != (void *) NULL);
- return(memset(memory,byte,size));
+ while (n-- != 0)
+ *p++=(unsigned char) c;
+ return(memory);
}
/*