code:
This patch enables building gcc-2.95.3 using TCC and Mes C Library.

  * Disable building DOC
  * Avoid running `fixproto'.
  * Force running `fixinc'.
  * Replace Makefile trickery of creating an libgcc1.a archive, then
    extracting the .o files later to create a new libgcc2.a archive.
    Instead, keep temporary .o files.

Upstream status: Not presented upstream.

diff -purN -x foo.c -x BOOT -x BOOT-2 -x BOOT-strict -x .git -x Makefile -x config.status -x config.h -x BOOT -x BOOT-GCC ../gcc-2.95.3/gcc/Makefile.in gcc-2.95.3/gcc/Makefile.in
--- ../gcc-2.95.3/gcc/Makefile.in	2001-01-25 15:02:58.000000000 +0100
+++ gcc-2.95.3/gcc/Makefile.in	2018-06-23 11:46:03.525159181 +0200
@@ -221,7 +221,7 @@ RANLIB_TEST_FOR_TARGET = \
 SYSTEM_HEADER_DIR = /usr/include

 # Control whether to run fixproto.
-STMP_FIXPROTO = stmp-fixproto
+# STMP_FIXPROTO = stmp-fixproto

 # Test to see whether <limits.h> exists in the system header files.
 LIMITS_H_TEST = [ -f $(SYSTEM_HEADER_DIR)/limits.h ]
@@ -958,6 +958,7 @@ libgcc1.cross:
 # fragments.
 libgcc1.a: libgcc1.c $(CONFIG_H) $(LIB1FUNCS_EXTRA) config.status
 	-rm -f tmplibgcc1.a
+	mkdir -p libgcc1-o
 # Actually build it in tmplibgcc1.a, then rename at end,
 # so that libgcc1.a itself remains nonexistent if compilation is aborted.
 # -e causes any failing command to make this rule fail.
@@ -974,6 +975,7 @@ libgcc1.a: libgcc1.c $(CONFIG_H) $(LIB1F
 	  if [ $$? -eq 0 ] ; then true; else exit 1; fi; \
 	  mv libgcc1$(objext) $${name}$(objext); \
 	  $(OLDAR) $(OLDAR_FLAGS) tmplibgcc1.a $${name}$(objext); \
+	  mv $${name}$(objext) libgcc1-o; \
 	  rm -f $${name}$(objext); \
 	done
 # Some shells crash when a loop has no items.
@@ -994,6 +996,7 @@ libgcc1.a: libgcc1.c $(CONFIG_H) $(LIB1F
 	    if [ $$? -eq 0 ] ; then true; else exit 1; fi; \
 	    $(OLDAR) $(OLDAR_FLAGS) tmplibgcc1.a $${name}$(objext); \
 	    if [ $$? -eq 0 ] ; then true; else exit 1; fi; \
+	    mv $${name}$(objext) libgcc1-o; \
 	    rm -f $${name}.s $${name}$(objext); \
 	  else true; \
 	  fi; \
@@ -1024,6 +1027,7 @@ libgcc1-asm.a: libgcc2.ready config.stat
 	  if [ $$? -eq 0 ] ; then true; else exit 1; fi; \
 	  mv libgcc1$(objext) $${name}$(objext); \
 	  $(AR_FOR_TARGET) $(AR_FLAGS_FOR_TARGET) tmplibgcc1.a $${name}$(objext); \
+	  mv $${name}$(objext) libgcc1-o; \
 	  rm -f $${name}$(objext); \
 	done
 	-rm -f libgcc1.S
@@ -1062,6 +1066,7 @@ libgcc2.a: libgcc2.c libgcc2.ready $(CON
 # Actually build it in tmplibgcc2.a, then rename at end,
 # so that libgcc2.a itself remains nonexistent if compilation is aborted.
 	-rm -f tmplibgcc2.a
+	mkdir -p libgcc2-o
 # -e causes any failing command to make this rule fail.
 # -e doesn't work in certain shells, so we test $$? as well.
 # lynx has a broken ar, it always complains when the initial library is
@@ -1139,6 +1144,7 @@ libgcc2.a: libgcc2.c libgcc2.ready $(CON
 	    $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) -c $${file}; \
 	    if [ $$? -eq 0 ] ; then true; else exit 1; fi; \
 	    $(AR_FOR_TARGET) $(AR_FLAGS_FOR_TARGET) tmplibgcc2.a $${oname}$(objext); \
+	    mv $${oname}$(objext) libgcc2-o;\
 	    rm -f $${name}.s $${oname}$(objext); \
 	  fi; \
 	done
@@ -1156,7 +1162,7 @@ libgcc.a: $(LIBGCC1) $(LIBGCC2)
 	-rm -rf tmplibgcc.a libgcc.a tmpcopy
 	mkdir tmpcopy
 	-if [ x$(LIBGCC1) != x ];			\
-	then (cd tmpcopy; $(AR_FOR_TARGET) x ../$(LIBGCC1));	\
+	then cp -v libgcc1-o/*.o tmpcopy;		\
 	else true;					\
 	fi
 # Some versions of ar (specifically the one in RISC/os 5.x), create an
@@ -1164,7 +1170,7 @@ libgcc.a: $(LIBGCC1) $(LIBGCC2)
 # the second ar command tries to overwrite this file.  To avoid the error
 # message from ar, we make sure all files are writable.
 	-(cd tmpcopy; chmod +w * > /dev/null 2>&1)
-	(cd tmpcopy; $(AR_FOR_TARGET) x ../$(LIBGCC2))
+	cp -v libgcc2-o/*.o tmpcopy
 	(cd tmpcopy; $(AR_FOR_TARGET) $(AR_FLAGS_FOR_TARGET) ../tmplibgcc.a *$(objext))
 	rm -rf tmpcopy
 	-if $(RANLIB_TEST_FOR_TARGET) ; then \
@@ -2093,14 +2099,18 @@ gcov$(exeext): $(GCOV_OBJS) $(LIBDEPS)
 # s-* so that mostlyclean does not force the include directory to
 # be rebuilt.

+# STMP_FIXINC = @STMP_FIXINC@
+STMP_FIXINC = stmp-fixinc
+
 # Build the include directory including float.h (which no longer depends upon
 # enquire).
-stmp-int-hdrs: stmp-fixinc $(USER_H) xlimits.h
+stmp-int-hdrs: $(STMP_FIXINC) $(USER_H) xlimits.h
 # Copy in the headers provided with gcc.
 # The sed command gets just the last file name component;
 # this is necessary because VPATH could add a dirname.
 # Using basename would be simpler, but some systems don't have it.
 # The touch command is here to workaround an AIX/Linux NFS bug.
+	-if [ -d include ] ; then true; else mkdir include; chmod a+rx include; fi
 	for file in .. $(USER_H); do \
 	  if [ X$$file != X.. ]; then \
 	    realfile=`echo $$file | sed -e 's|.*/\([^/]*\)$$|\1|'`; \
@@ -2265,16 +2275,17 @@ stmp-fixproto: fixhdr.ready fixproto stm
 #
 # Remake the info files.

-doc: info
-info: cpp.info gcc.info lang.info
-
-cpp.info: $(srcdir)/cpp.texi
-	$(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o cpp.info $(srcdir)/cpp.texi
-
-gcc.info: $(srcdir)/gcc.texi $(srcdir)/extend.texi $(srcdir)/install.texi \
-	  $(srcdir)/invoke.texi $(srcdir)/md.texi $(srcdir)/rtl.texi \
-	  $(srcdir)/tm.texi $(srcdir)/gcov.texi
-	$(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o gcc.info $(srcdir)/gcc.texi
+doc:
+# doc: info
+# info: cpp.info gcc.info lang.info
+
+# cpp.info: $(srcdir)/cpp.texi
+# 	$(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o cpp.info $(srcdir)/cpp.texi
+
+# gcc.info: $(srcdir)/gcc.texi $(srcdir)/extend.texi $(srcdir)/install.texi \
+# 	  $(srcdir)/invoke.texi $(srcdir)/md.texi $(srcdir)/rtl.texi \
+# 	  $(srcdir)/tm.texi $(srcdir)/gcov.texi
+# 	$(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o gcc.info $(srcdir)/gcc.texi

 dvi: gcc.dvi cpp.dvi lang.dvi


code:
This patch enables building gcc-4.6.4 using gcc-2.95.3 and glibc-2.2.5

  * Tweak Makefile to allow overriding NATIVE_SYSTEM_HEADER_DIR using #:makeflags
  * Add missing limits.h include.
  * Add SSIZE_MAX define.  The SSIZE_MAX define has been added to Mes
    upstream and can be removed with the next Mes release.
  * Remove -fbuilding-libgcc flag, it assumes features being present from a
    newer gcc or glibc.
  * [MES_BOOTSTRAP_GCC]: Disable threads harder.

Upstream status: not presented upstream.

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index f3cc49fdb18..bc5718fc9a6 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -440,7 +440,7 @@ LINKER_PLUGIN_API_H = $(srcdir)/../include/plugin-api.h
 LTO_SYMTAB_H = $(srcdir)/../include/lto-symtab.h

 # Default native SYSTEM_HEADER_DIR, to be overridden by targets.
-NATIVE_SYSTEM_HEADER_DIR = /usr/include
+# NATIVE_SYSTEM_HEADER_DIR = /usr/include
 # Default cross SYSTEM_HEADER_DIR, to be overridden by targets.
 CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@

diff --git a/gcc/config/host-linux.c b/gcc/config/host-linux.c
index 94b7a0b89a7..ab2baab55ca 100644
--- a/gcc/config/host-linux.c
+++ b/gcc/config/host-linux.c
@@ -23,6 +23,12 @@
 #include "hosthooks.h"
 #include "hosthooks-def.h"

+// ../.././gcc/config/host-linux.c:213: `SSIZE_MAX' undeclared (first
+// use in this function)
+#include <limits.h>
+#ifndef	SSIZE_MAX
+# define SSIZE_MAX	LONG_MAX
+#endif

 /* Linux has a feature called exec-shield-randomize that perturbs the
    address of non-fixed mapped segments by a (relatively) small amount.
diff --git a/libgcc/generic-morestack-thread.c b/libgcc/generic-morestack-thread.c
index bbe6dd12b5a..1d1d48223d7 100644
--- a/libgcc/generic-morestack-thread.c
+++ b/libgcc/generic-morestack-thread.c
@@ -34,7 +34,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    will want to define inhibit_libc while building a compiler which
    can build glibc.  */

-#ifndef inhibit_libc
+#if 0 //!defined (inhibit_libc) && !MES_BOOTSTRAP_GCC

 #include <errno.h>
 #include <pthread.h>

repo_name: maximed/guix

license: mit


code:
Search path environment variables for cross-compilers.  See the discussion
at <http://gcc.gnu.org/ml/gcc/2013-02/msg00124.html>.

Note: Touch 'C_INCLUDE_PATH' et al. rather than 'CPATH', as discussed
at <http://bugs.gnu.org/22186>.

--- a/gcc/incpath.c
+++ b/gcc/incpath.c
@@ -461,8 +461,8 @@ register_include_chains (cpp_reader *pfile, const char *sysroot,
 			 int stdinc, int cxx_stdinc, int verbose)
 {
   static const char *const lang_env_vars[] =
-    { "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH",
-      "OBJC_INCLUDE_PATH", "OBJCPLUS_INCLUDE_PATH" };
+    { "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH",
+      "CROSS_OBJC_INCLUDE_PATH", "CROSS_OBJCPLUS_INCLUDE_PATH" };
   cpp_options *cpp_opts = cpp_get_options (pfile);
   size_t idx = (cpp_opts->objc ? 2: 0);

@@ -473,7 +473,7 @@ register_include_chains (cpp_reader *pfile, const char *sysroot,

   /* CPATH and language-dependent environment variables may add to the
      include chain.  */
-  add_env_var_paths ("CPATH", BRACKET);
+  add_env_var_paths ("CROSS_CPATH", BRACKET);
   add_env_var_paths (lang_env_vars[idx], SYSTEM);

   target_c_incpath.extra_pre_includes (sysroot, iprefix, stdinc);
diff --git a/gcc/system.h b/gcc/system.h
index 42bc509..af3b9ad 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -1063,4 +1063,6 @@ helper_const_non_const_cast (const char *p)
 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT.  */
 #include "hwint.h"

+#define LIBRARY_PATH_ENV "CROSS_LIBRARY_PATH"
+
 #endif /* ! GCC_SYSTEM_H */
diff --git a/gcc/tlink.c b/gcc/tlink.c
index bc358b8..ad6242f 100644
--- a/gcc/tlink.c
+++ b/gcc/tlink.c
@@ -458,7 +458,7 @@ recompile_files (void)
   file *f;

   putenv (xstrdup ("COMPILER_PATH="));
-  putenv (xstrdup ("LIBRARY_PATH="));
+  putenv (xstrdup (LIBRARY_PATH_ENV "="));

   while ((f = file_pop ()) != NULL)
     {
diff --git a/gcc/gcc.c b/gcc/gcc.c
index adbf0c4..70448c6 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3853,7 +3853,7 @@ process_command (unsigned int decoded_options_count,
     }

   temp = getenv (LIBRARY_PATH_ENV);
-  if (temp && *cross_compile == '0')
+  if (temp)
     {
       const char *startp, *endp;
       char *nstore = (char *) alloca (strlen (temp) + 3);


code:
This patch was taken from the official GCC git repository.
X-Git-Url: https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff_plain;f=contrib%2Ftexi2pod.pl;h=91bdbb5cea933d0381f2924ab94490fca31d5800;hp=eba1bcaa3cffa78b46030b219d04fe7d68367658;hb=67b56c905078d49d3e4028085e5cb1e1fb87a8aa;hpb=2f508a78310caab123e9794d3dcfe41f2769449b

It fixes a defect in the contrib/texi2pod.pl script that prevented generating
manual pages. It was corrected in the GCC 6.X series.

diff --git a/contrib/texi2pod.pl b/contrib/texi2pod.pl
index eba1bca..91bdbb5 100755
--- a/contrib/texi2pod.pl
+++ b/contrib/texi2pod.pl
@@ -316,7 +316,7 @@ while(<$inf>) {
 	@columns = ();
 	for $column (split (/\s*\@tab\s*/, $1)) {
 	    # @strong{...} is used a @headitem work-alike
-	    $column =~ s/^\@strong{(.*)}$/$1/;
+	    $column =~ s/^\@strong\{(.*)\}$/$1/;
 	    push @columns, $column;
 	}
 	$_ = "\n=item ".join (" : ", @columns)."\n";


code:
Remove use of deprecated ustat interface in glibc 2.28:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85835

Taken from upstream:

https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=260684

diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
index 858bb2184505..de18e56d11cf 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -157,7 +157,6 @@ typedef struct user_fpregs elf_fpregset_t;
 # include <sys/procfs.h>
 #endif
 #include <sys/user.h>
-#include <sys/ustat.h>
 #include <linux/cyclades.h>
 #include <linux/if_eql.h>
 #include <linux/if_plip.h>
@@ -250,7 +249,19 @@ namespace __sanitizer {
 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD

 #if SANITIZER_LINUX && !SANITIZER_ANDROID
-  unsigned struct_ustat_sz = sizeof(struct ustat);
+  // Use pre-computed size of struct ustat to avoid <sys/ustat.h> which
+  // has been removed from glibc 2.28.
+#if defined(__aarch64__) || defined(__s390x__) || defined (__mips64) \
+  || defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) \
+  || defined(__x86_64__)
+#define SIZEOF_STRUCT_USTAT 32
+#elif defined(__arm__) || defined(__i386__) || defined(__mips__) \
+  || defined(__powerpc__) || defined(__s390__)
+#define SIZEOF_STRUCT_USTAT 20
+#else
+#error Unknown size of struct ustat
+#endif
+  unsigned struct_ustat_sz = SIZEOF_STRUCT_USTAT;
   unsigned struct_rlimit64_sz = sizeof(struct rlimit64);
   unsigned struct_statvfs64_sz = sizeof(struct statvfs64);
 #endif // SANITIZER_LINUX && !SANITIZER_ANDROID


code:
GCC 4.9 and later have libvtv and, just like libstdc++ (see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32354), it doesn't
have $libdir in its RUNPATH, but it NEEDs libgcc_s.  This patch
fixes that.

--- gcc-4.9.2/libvtv/Makefile.in	2014-10-30 09:28:58.000000000 +0100
+++ gcc-4.9.2/libvtv/Makefile.in	2015-04-30 09:51:04.161129705 +0200
@@ -15,6 +15,7 @@

 @SET_MAKE@

+AM_LDFLAGS = -Wl,-rpath=$(libdir)

 VPATH = @srcdir@
 pkgdatadir = $(datadir)/@PACKAGE@


code:
Make sure that statements such as:

  strcpy (dst, "/gnu/store/…");

or

  static const char str[] = "/gnu/store/…";
  …
  strcpy (dst, str);

do not result in chunked /gnu/store strings that are undetectable by
Guix's GC and its grafting code.  See <https://bugs.gnu.org/24703>
and <https://bugs.gnu.org/30395>.

--- gcc-5.3.0/gcc/builtins.c	2016-10-18 10:50:46.080616285 +0200
+++ gcc-5.3.0/gcc/builtins.c	2016-11-09 15:26:43.693042737 +0100
@@ -3192,6 +3192,58 @@ determine_block_size (tree len, rtx len_
 			  GET_MODE_MASK (GET_MODE (len_rtx)));
 }

+extern void debug_tree (tree);
+
+/* Return true if STR contains the string "/gnu/store".  */
+
+bool
+store_reference_p (tree str)
+{
+  if (getenv ("GUIX_GCC_DEBUG") != NULL)
+    debug_tree (str);
+
+  if (TREE_CODE (str) == ADDR_EXPR)
+    str = TREE_OPERAND (str, 0);
+
+  if (TREE_CODE (str) == VAR_DECL
+      && TREE_STATIC (str)
+      && TREE_READONLY (str))
+    {
+      /* STR may be a 'static const' variable whose initial value
+         is a string constant.  See <https://bugs.gnu.org/30395>.  */
+      str = DECL_INITIAL (str);
+      if (str == NULL_TREE)
+        return false;
+    }
+
+  if (TREE_CODE (str) != STRING_CST)
+    return false;
+
+  int len;
+  const char *store;
+
+  store = getenv ("NIX_STORE") ? getenv ("NIX_STORE") : "/gnu/store";
+  len = strlen (store);
+
+  /* Size of the hash part of store file names, including leading slash and
+     trailing hyphen.  */
+  const int hash_len = 34;
+
+  if (TREE_STRING_LENGTH (str) < len + hash_len)
+    return false;
+
+  /* We cannot use 'strstr' because 'TREE_STRING_POINTER' returns a string
+     that is not necessarily NUL-terminated.  */
+
+  for (int i = 0; i < TREE_STRING_LENGTH (str) - (len + hash_len); i++)
+    {
+      if (strncmp (TREE_STRING_POINTER (str) + i, store, len) == 0)
+	return true;
+    }
+
+  return false;
+}
+
 /* Helper function to do the actual work for expand_builtin_memcpy.  */

 static rtx
@@ -3207,6 +3243,13 @@ expand_builtin_memcpy_args (tree dest, t
   unsigned HOST_WIDE_INT max_size;
   unsigned HOST_WIDE_INT probable_max_size;

+  /* Do not emit block moves, which translate to the 'movabs' instruction on
+     x86_64, when SRC refers to store items.  That way, store references
+     remain visible to the Guix GC and grafting code.  See
+     <https://bugs.gnu.org/24703>.  */
+  if (store_reference_p (src))
+    return NULL_RTX;
+
   /* If DEST is not a pointer type, call the normal function.  */
   if (dest_align == 0)
     return NULL_RTX;

--- gcc-5.5.0/gcc/gimple-fold.c	2018-03-20 11:36:16.709442004 +0100
+++ gcc-5.5.0/gcc/gimple-fold.c	2018-03-20 11:46:43.838487065 +0100
@@ -769,6 +769,8 @@ var_decl_component_p (tree var)
   return SSA_VAR_P (inner);
 }

+extern bool store_reference_p (tree);
+
 /* Fold function call to builtin mem{{,p}cpy,move}.  Return
    false if no simplification can be made.
    If ENDP is 0, return DEST (like memcpy).
@@ -1099,6 +1101,9 @@ gimple_fold_builtin_memory_op (gimple_st
       if (!srctype)
 	return false;

+      if (store_reference_p (src))
+        return false;
+
       src_align = get_pointer_alignment (src);
       dest_align = get_pointer_alignment (dest);
       if (dest_align < TYPE_ALIGN (desttype)


code:
Disable some image comparison tests on architectures such as i686
where intermediate floating-point operations are done with 80-bit long
doubles, and typically later rounded to 64-bit doubles.  This double
rounding causes small differences in the resulting pixel values
compared with other architectures, causing the image comparisons to
fail.

Patch by Mark H Weaver <mhw@netris.org>.

diff -ru libgd-2.2.3.orig/tests/gdimagecopyresampled/basic_alpha.c libgd-2.2.3/tests/gdimagecopyresampled/basic_alpha.c
--- libgd-2.2.3.orig/tests/gdimagecopyresampled/basic_alpha.c	2016-07-21 04:06:42.000000000 -0400
+++ libgd-2.2.3/tests/gdimagecopyresampled/basic_alpha.c	2016-07-29 13:50:56.214877446 -0400
@@ -1,5 +1,6 @@
 /* Testing basic gdImageCopyResampled() functionality with alpha channel */

+#include <float.h>
 #include "gd.h"
 #include "gdtest.h"

@@ -33,7 +34,8 @@
 	gdImageCopyResampled(copy, im, 0,0, 0,0, 200,200, 400,300);
 	gdImageDestroy(im);

-	gdAssertImageEqualsToFile("gdimagecopyresampled/basic_alpha_exp.png", copy);
+	if (FLT_EVAL_METHOD != 2)
+		gdAssertImageEqualsToFile("gdimagecopyresampled/basic_alpha_exp.png", copy);

 	gdImageDestroy(copy);
 	return gdNumFailures();
diff -ru libgd-2.2.3.orig/tests/gdimagecopyresampled/bug00201.c libgd-2.2.3/tests/gdimagecopyresampled/bug00201.c
--- libgd-2.2.3.orig/tests/gdimagecopyresampled/bug00201.c	2016-07-21 04:06:42.000000000 -0400
+++ libgd-2.2.3/tests/gdimagecopyresampled/bug00201.c	2016-07-29 13:50:30.638559003 -0400
@@ -1,3 +1,4 @@
+#include <float.h>
 #include "gd.h"
 #include "gdtest.h"

@@ -65,7 +66,8 @@
     gdImageDestroy(background);
     gdImageDestroy(scaled_logo);

-    gdAssertImageEqualsToFile("gdimagecopyresampled/bug00201_exp.png", img);
+    if (FLT_EVAL_METHOD != 2)
+        gdAssertImageEqualsToFile("gdimagecopyresampled/bug00201_exp.png", img);
     gdImageDestroy(img);
     return gdNumFailures();
 }
diff -ru libgd-2.2.3.orig/tests/gdimagerotate/bug00067.c libgd-2.2.3/tests/gdimagerotate/bug00067.c
--- libgd-2.2.3.orig/tests/gdimagerotate/bug00067.c	2016-06-18 05:42:16.000000000 -0400
+++ libgd-2.2.3/tests/gdimagerotate/bug00067.c	2016-07-29 13:50:07.566271765 -0400
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <float.h>
 #include "gd.h"

 #include "gdtest.h"
@@ -43,7 +44,7 @@

 		sprintf(filename, "bug00067_%03d_exp.png", angle);
 		path = gdTestFilePath2("gdimagerotate", filename);
-		if (!gdAssertImageEqualsToFile(path, exp)) {
+		if (FLT_EVAL_METHOD != 2 && !gdAssertImageEqualsToFile(path, exp)) {
 			gdTestErrorMsg("comparing rotated image to %s failed.\n", path);
 			error += 1;
 		}


code:
Taken from upstream, removed ChangeLog.

From 6930bffe3373690b3431d6291f9f7c116d6a1ec4 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Sat, 30 May 2020 18:35:59 +0000
Subject: [PATCH] hurd: fix gnu_debug_flag type
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes

../../gdb/gnu-nat.c:96:6: error: conflicting declaration ‘bool gnu_debug_flag’
   96 | bool gnu_debug_flag = false;
../../gdb/gnu-nat.c: In function ‘void _initialize_gnu_nat()’:
../../gdb/gnu-nat.c:3511:7: error: cannot

gdb/ChangeLog:

	* gnu-nat.h (gnu_debug_flag): Set type to bool.
---
 gdb/ChangeLog | 4 ++++
 gdb/gnu-nat.h | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/gnu-nat.h b/gdb/gnu-nat.h
index 77c57817b2..766f716587 100644
--- a/gdb/gnu-nat.h
+++ b/gdb/gnu-nat.h
@@ -111,7 +111,7 @@ extern char *proc_string (struct proc *proc);
 	      __proc_pid (__proc), __proc->tid, \
 	      host_address_to_string (__proc) , ##args); } while (0)

-extern int gnu_debug_flag;
+extern bool gnu_debug_flag;

 #define debug(msg, args...) \
  do { if (gnu_debug_flag) \
--
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com

commit 366f550a593c7e6bae3699a4b6d65fe937af5603
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sat May 30 18:41:30 2020 +0000

    hurd: add missing include

    Fixes

    ../../gdb/gnu-nat.c:2522:14: error: ‘target_gdbarch’ was not declared in this scope; did you mean ‘target_detach’?
     2522 |    paddress (target_gdbarch (), memaddr), pulongest (len),

    gdb/Changelog:

            * gnu-nat.c: Include "gdbarch.h".

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index 3b438a9a43..9b93488b41 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -64,6 +64,7 @@ extern "C"
 #include "language.h"
 #include "target.h"
 #include "gdbsupport/gdb_wait.h"
+#include "gdbarch.h"
 #include "gdbcmd.h"
 #include "gdbcore.h"
 #include "gdbthread.h"


code:
Fix CVE-2020-29385.  Note that we omit the binary test file
tests/test-images/fail/hang_114.gif from the following commit, to avoid
requiring 'git' to apply the patch.

From bdd3acbd48a575d418ba6bf1b32d7bda2fae1c81 Mon Sep 17 00:00:00 2001
From: Robert Ancell <robert.ancell@canonical.com>
Date: Mon, 30 Nov 2020 12:26:12 +1300
Subject: [PATCH] gif: Fix LZW decoder accepting invalid LZW code.

The code value after a reset wasn't being validated, which means we would
accept invalid codes. This could cause an infinite loop in the decoder.

Fixes CVE-2020-29385

Fixes https://gitlab.gnome.org/GNOME/gdk-pixbuf/-/issues/164
---
 gdk-pixbuf/lzw.c                    |  13 +++++++------
 tests/test-images/fail/hang_114.gif | Bin 0 -> 5561 bytes
 2 files changed, 7 insertions(+), 6 deletions(-)
 create mode 100644 tests/test-images/fail/hang_114.gif

diff --git a/gdk-pixbuf/lzw.c b/gdk-pixbuf/lzw.c
index 9e052a6f7..105daf2b1 100644
--- a/gdk-pixbuf/lzw.c
+++ b/gdk-pixbuf/lzw.c
@@ -195,19 +195,20 @@ lzw_decoder_feed (LZWDecoder *self,
                                 if (self->last_code != self->clear_code && self->code_table_size < MAX_CODES) {
                                         if (self->code < self->code_table_size)
                                                 add_code (self, self->code);
-                                        else if (self->code == self->code_table_size)
+                                        else
                                                 add_code (self, self->last_code);
-                                        else {
-                                                /* Invalid code received - just stop here */
-                                                self->last_code = self->eoi_code;
-                                                return output_length;
-                                        }

                                         /* When table is full increase code size */
                                         if (self->code_table_size == (1 << self->code_size) && self->code_size < LZW_CODE_MAX)
                                                 self->code_size++;
                                 }

+                                /* Invalid code received - just stop here */
+                                if (self->code >= self->code_table_size) {
+                                        self->last_code = self->eoi_code;
+                                        return output_length;
+                                }
+
                                 /* Convert codeword into indexes */
                                 n_written += write_indexes (self, output + n_written, output_length - n_written);
                         }


code:
This patch ensures '.desktop' files are picked up in the system profile
and not in the directories listed in $XDG_DATA_DIRS.  The latter includes
'gnome-session.desktop', which should be used if it's in
/run/current-system/profile, and only then.

Fixes <https://bugs.gnu.org/37831>.

diff -ur a/daemon/gdm-session.c b/daemon/gdm-session.c
--- a/daemon/gdm-session.c	2019-09-25 10:40:24.000000000 -0400
+++ b/daemon/gdm-session.c	2020-04-18 18:30:02.671856808 -0400
@@ -348,24 +348,18 @@
         GArray *search_array = NULL;
         char **search_dirs;
         int i;
-        const gchar * const *system_data_dirs = g_get_system_data_dirs ();

         static const char *x_search_dirs[] = {
                 "/etc/X11/sessions/",
                 DMCONFDIR "/Sessions/",
                 DATADIR "/gdm/BuiltInSessions/",
-                DATADIR "/xsessions/",
+                "/run/current-system/profile/share/xsessions/"
         };

         static const char *wayland_search_dir = DATADIR "/wayland-sessions/";

         search_array = g_array_new (TRUE, TRUE, sizeof (char *));

-        for (i = 0; system_data_dirs[i]; i++) {
-                gchar *dir = g_build_filename (system_data_dirs[i], "xsessions", NULL);
-                g_array_append_val (search_array, dir);
-        }
-
         g_array_append_vals (search_array, x_search_dirs, G_N_ELEMENTS (x_search_dirs));

 #ifdef ENABLE_WAYLAND_SUPPORT
@@ -373,16 +367,7 @@
 #ifdef ENABLE_USER_DISPLAY_SERVER
                 g_array_prepend_val (search_array, wayland_search_dir);

-                for (i = 0; system_data_dirs[i]; i++) {
-                        gchar *dir = g_build_filename (system_data_dirs[i], "wayland-sessions", NULL);
-                        g_array_insert_val (search_array, i, dir);
-                }
 #else
-                for (i = 0; system_data_dirs[i]; i++) {
-                        gchar *dir = g_build_filename (system_data_dirs[i], "wayland-sessions", NULL);
-                        g_array_append_val (search_array, dir);
-                }
-
                 g_array_append_val (search_array, wayland_search_dir);
 #endif
         }
diff -ur a/libgdm/gdm-sessions.c b/libgdm/gdm-sessions.c
--- a/libgdm/gdm-sessions.c	2019-10-07 04:53:35.000000000 -0400
+++ b/libgdm/gdm-sessions.c	2020-04-18 18:31:42.491348691 -0400
@@ -245,19 +245,12 @@
                 "/etc/X11/sessions/",
                 DMCONFDIR "/Sessions/",
                 DATADIR "/gdm/BuiltInSessions/",
-                DATADIR "/xsessions/",
+                "/run/current-system/profile/share/xsessions/"
         };

         names_seen_before = g_hash_table_new (g_str_hash, g_str_equal);
         xorg_search_array = g_ptr_array_new_with_free_func (g_free);

-        const gchar * const *system_data_dirs = g_get_system_data_dirs ();
-
-        for (i = 0; system_data_dirs[i]; i++) {
-                session_dir = g_build_filename (system_data_dirs[i], "xsessions", NULL);
-                g_ptr_array_add (xorg_search_array, session_dir);
-        }
-
         for (i = 0; i < G_N_ELEMENTS (xorg_search_dirs); i++) {
                 g_ptr_array_add (xorg_search_array, g_strdup (xorg_search_dirs[i]));
         }
@@ -269,11 +262,6 @@

         wayland_search_array = g_ptr_array_new_with_free_func (g_free);

-        for (i = 0; system_data_dirs[i]; i++) {
-                session_dir = g_build_filename (system_data_dirs[i], "wayland-sessions", NULL);
-                g_ptr_array_add (wayland_search_array, session_dir);
-        }
-
         for (i = 0; i < G_N_ELEMENTS (wayland_search_dirs); i++) {
                 g_ptr_array_add (wayland_search_array, g_strdup (wayland_search_dirs[i]));
         }


code:
From d4e86dc91e1d8a940dc40872fe94ef9ac0fed1b5 Mon Sep 17 00:00:00 2001
From: Michael Gratton <mike@vee.net>
Date: Tue, 25 Aug 2020 03:54:09 +0000
Subject: [PATCH] Merge branch 'mjog/866-self-signed-certificates' into
 'mainline'

Fix invalid certificate pinning when GCR support is unavailable

Closes #866

See merge request GNOME/geary!529

(cherry picked from commit 423a55b00f1dc6bee9dc17e67c0aea6f42387a77)

5088adfe Application.CertificateManager: Rename some methods for clarity
0d957559 Application.CertificateManager: Check locally pinned certs for equality
---
 .../application-certificate-manager.vala      | 44 +++++++++----------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/client/application/application-certificate-manager.vala b/src/client/application/application-certificate-manager.vala
index 4881d73c0..65f6af4fa 100644
--- a/src/client/application/application-certificate-manager.vala
+++ b/src/client/application/application-certificate-manager.vala
@@ -381,8 +381,8 @@ private class Application.TlsDatabase : GLib.TlsDatabase {
         GLib.TlsCertificateFlags ret = this.parent.verify_chain(
             chain, purpose, identity, interaction, flags, cancellable
         );
-        if (should_verify(ret, purpose, identity) &&
-            verify(chain, identity, cancellable)) {
+        if (check_pinned(ret, purpose, identity) &&
+            is_pinned(chain, identity, cancellable)) {
             ret = 0;
         }
         return ret;
@@ -399,16 +399,16 @@ private class Application.TlsDatabase : GLib.TlsDatabase {
         GLib.TlsCertificateFlags ret = yield this.parent.verify_chain_async(
             chain, purpose, identity, interaction, flags, cancellable
         );
-        if (should_verify(ret, purpose, identity) &&
-            yield verify_async(chain, identity, cancellable)) {
+        if (check_pinned(ret, purpose, identity) &&
+            yield is_pinned_async(chain, identity, cancellable)) {
             ret = 0;
         }
         return ret;
     }

-    private inline bool should_verify(GLib.TlsCertificateFlags parent_ret,
-                                      string purpose,
-                                      GLib.SocketConnectable? identity) {
+    private inline bool check_pinned(GLib.TlsCertificateFlags parent_ret,
+                                     string purpose,
+                                     GLib.SocketConnectable? identity) {
         // If the parent didn't verify, check for a locally pinned
         // cert if it looks like we should, but always reject revoked
         // certs
@@ -420,22 +420,22 @@ private class Application.TlsDatabase : GLib.TlsDatabase {
         );
     }

-    private bool verify(GLib.TlsCertificate chain,
-                        GLib.SocketConnectable identity,
-                        GLib.Cancellable? cancellable)
+    private bool is_pinned(GLib.TlsCertificate chain,
+                           GLib.SocketConnectable identity,
+                           GLib.Cancellable? cancellable)
         throws GLib.Error {
-        bool is_verified = false;
+        bool is_pinned = false;
         string id = to_name(identity);
         TrustContext? context = null;
         lock (this.pinned_certs) {
             context = this.pinned_certs.get(id);
             if (context != null) {
-                is_verified = true;
+                is_pinned = context.certificate.is_same(chain);
             } else {
                 // Cert not found in memory, check with GCR if
                 // enabled.
                 if (this.use_gcr) {
-                    is_verified = gcr_trust_is_certificate_pinned(
+                    is_pinned = gcr_trust_is_certificate_pinned(
                         new Gcr.SimpleCertificate(chain.certificate.data),
                         GLib.TlsDatabase.PURPOSE_AUTHENTICATE_SERVER,
                         id,
@@ -443,7 +443,7 @@ private class Application.TlsDatabase : GLib.TlsDatabase {
                     );
                 }

-                if (!is_verified) {
+                if (!is_pinned) {
                     // Cert is not pinned in memory or in GCR, so look
                     // for it on disk. Do this even if GCR support is
                     // enabled, since if the cert was previously saved
@@ -453,7 +453,7 @@ private class Application.TlsDatabase : GLib.TlsDatabase {
                             this.store_dir, id, cancellable
                         );
                         this.pinned_certs.set(id, context);
-                        is_verified = true;
+                        is_pinned = context.certificate.is_same(chain);
                     } catch (GLib.IOError.NOT_FOUND err) {
                         // Cert was not found saved, so it not pinned
                     } catch (GLib.Error err) {
@@ -465,18 +465,18 @@ private class Application.TlsDatabase : GLib.TlsDatabase {
                 }
             }
         }
-        return is_verified;
+        return is_pinned;
     }

-    private async bool verify_async(GLib.TlsCertificate chain,
-                                    GLib.SocketConnectable identity,
-                                    GLib.Cancellable? cancellable)
+    private async bool is_pinned_async(GLib.TlsCertificate chain,
+                                       GLib.SocketConnectable identity,
+                                       GLib.Cancellable? cancellable)
         throws GLib.Error {
-        bool is_valid = false;
+        bool pinned = false;
         yield Geary.Nonblocking.Concurrent.global.schedule_async(() => {
-                is_valid = verify(chain, identity, cancellable);
+                pinned = is_pinned(chain, identity, cancellable);
             }, cancellable);
-        return is_valid;
+        return pinned;
     }

     private TrustContext? lookup_id(string id) {
--
GitLab


code:
commit 6574665f9d6c0757e8f55ccb465afbcaa90bf019
Author: Timotej Lazar <timotej.lazar@araneo.si>
Date:   Wed Aug 19 19:36:02 2020 +0200

    test: normalize flags reported by dumpe2fs

    Filesystem flags depend on the system – usually signed_directory_hash,
    but unsigned_directory_hash at least on arm64.

    Signed-off-by: Timotej Lazar <timotej.lazar@araneo.si>

diff --git a/test/basic-images.test b/test/basic-images.test
index f6685e1..cb104c3 100755
--- a/test/basic-images.test
+++ b/test/basic-images.test
@@ -158,6 +158,8 @@ check_ext() {
 	# format change
 	csum2="Group 0: (Blocks 1-4095) \\[ITABLE_ZEROED\\]\|  Checksum .*, unused inodes 205"
 	dumpe2fs "${1}" | grep -v "^\($uuid\|$seed\|$csum1\|$csum2\)" > "dump" &&
+	# some architectures (including arm64) use unsigned char
+	sed -i 's/un\(signed_directory_hash\)/\1/' "dump" &&
 	# fixup for ext3 journal size with old tune2fs
 	sed -i 's/^\(Journal size:             \)1029k$/\11024k/' "dump" &&
 	# output format changed with some version


code:
Allow the configuration file to be specified via an environment variable.

--- geoclue-2.1.10/src/gclue-config.c	2015-04-07 09:50:07.721074380 +0200
+++ geoclue-2.1.10/src/gclue-config.c	2015-04-07 10:27:26.613171960 +0200
@@ -235,6 +235,11 @@
 gclue_config_init (GClueConfig *config)
 {
         GError *error = NULL;
+	const char *config_file_path;
+
+	config_file_path = g_getenv ("GEOCLUE_CONFIG_FILE");
+	if (config_file_path == NULL)
+	  config_file_path = CONFIG_FILE_PATH;

         config->priv =
                 G_TYPE_INSTANCE_GET_PRIVATE (config,
@@ -242,7 +247,7 @@
                                             GClueConfigPrivate);
         config->priv->key_file = g_key_file_new ();
         g_key_file_load_from_file (config->priv->key_file,
-                                   CONFIG_FILE_PATH,
+                                   config_file_path,
                                    0,
                                    &error);
         if (error != NULL) {


code:
ghc runtime by default (otherwise depending on a "configure" option)
does memory allocation on their own by first mmapping a 1 TB range of
memory into the process and then parceling out chunks from it.

If one of the chunks is not needed, the kernel needs to be informed -
otherwise the system would quickly run out of available RAM.

ghc does that via madvise(2).

There are two options when doing this informing:

MADV_FREE - Means "I don't need this range or the data in it any more".
Kernel promises to fail later accesses to it.

MADV_DONTNEED - Means "I don't need this range right now - and I don't
need the data in it anymore". Kernel promises to make later accesses to
it succeed (if necessary by providing a new page initialized with zeroes).

MADV_FREE was introduced in Linux 4.5.
glibc 2.25 and later always define MADV_FREE.

Unpatched ghc 8.0.2 will use either MADV_FREE or MADV_DONTNEED, determined
at ghc compile time.  Which of them will actually succeed is determined
by the Linux kernel at run time.

This patch makes ghc try MADV_FREE.  If it doesn't work, it falls back to
MADV_DONTNEED.

The end result is that ghc programs free their memory with Linux < 4.5 again.

See https://git.haskell.org/ghc.git/commitdiff/6576bf83cdf4eac05eb88a24aa934a736c91e3da for more information.
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -541,11 +541,24 @@ void osDecommitMemory(void *at, W_ size)

 #ifdef MADV_FREE
     // Try MADV_FREE first, FreeBSD has both and MADV_DONTNEED
-    // just swaps memory out
+    // just swaps memory out. Linux >= 4.5 has both DONTNEED and FREE; either
+    // will work as they both allow the system to free anonymous pages.
+    // It is important that we try both methods as the kernel which we were
+    // built on may differ from the kernel we are now running on.
     r = madvise(at, size, MADV_FREE);
-#else
-    r = madvise(at, size, MADV_DONTNEED);
+    if(r < 0) {
+        if (errno == EINVAL) {
+            // Perhaps the system doesn't support MADV_FREE; fall-through and
+            // try MADV_DONTNEED.
+        } else {
+            sysErrorBelch("unable to decommit memory");
+        }
+    } else {
+        return;
+    }
 #endif
+
+    r = madvise(at, size, MADV_DONTNEED);
     if(r < 0)
         sysErrorBelch("unable to decommit memory");
 }


code:
The QuickCheck library swapped the order of the arguments of the 'cover'
function in version 2.12.  Version 0.3.4 of the Diff library still uses
the old argument order.  Swapping the argument order makes Diff work
with newer versions of QuickCheck.

See <https://github.com/commercialhaskell/stackage/issues/4289> for the
upstream bug report.

diff -ruN a/test/Test.hs b/test/Test.hs
--- a/test/Test.hs	2016-04-23 01:21:45.000000000 -0400
+++ b/test/Test.hs	2019-11-01 19:13:04.590770903 -0400
@@ -134,7 +134,7 @@
 prop_ppDiffR (DiffInput le ri) =
     let haskDiff=ppDiff $ getGroupedDiff le ri
         utilDiff= unsafePerformIO (runDiff (unlines le) (unlines ri))
-    in  cover (haskDiff == utilDiff) 90 "exact match" $
+    in  cover 90 (haskDiff == utilDiff) "exact match" $
                 classify (haskDiff == utilDiff) "exact match"
                         (div ((length haskDiff)*100) (length utilDiff) < 110) -- less than 10% bigger
     where


code:
This patch is taken from upstream.  It fixes documentation generation.
The patch has been lightly adapted to apply to the release tarball, but
the commit message was left untouched, so it refers to some changes not
included in the patch.

From 0d9a81e20238a6b72f9f5c005f1f7e9cf05f6fb9 Mon Sep 17 00:00:00 2001
From: Alec Theriault <alec.theriault@gmail.com>
Date: Sat, 27 Oct 2018 10:05:04 -0700
Subject: [PATCH] Fix documentation in `haddock-api` (#957)

* Fix misplaced Haddocks in Haddock itself

Haddock should be able to generate documentation for 'haddock-api'
again.

* Make CI check that documentation can be built.

* Add back a doc that is OK
---
 .travis.yml                               |  3 +++
 haddock-api/src/Haddock/Backends/LaTeX.hs | 10 +++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/Haddock/Backends/LaTeX.hs b/src/Haddock/Backends/LaTeX.hs
index 4e0e6eba..613c6deb 100644
--- a/src/Haddock/Backends/LaTeX.hs
+++ b/src/Haddock/Backends/LaTeX.hs
@@ -243,8 +243,8 @@ ppDocGroup lev doc = sec lev <> braces doc

 -- | Given a declaration, extract out the names being declared
 declNames :: LHsDecl DocNameI
-          -> ( LaTeX           -- ^ to print before each name in an export list
-             , [DocName]       -- ^ names being declared
+          -> ( LaTeX           --   to print before each name in an export list
+             , [DocName]       --   names being declared
              )
 declNames (L _ decl) = case decl of
   TyClD _ d  -> (empty, [tcdName d])
@@ -444,9 +444,9 @@ ppLPatSig doc docnames ty unicode
 -- arguments as needed.
 ppTypeOrFunSig :: HsType DocNameI
                -> DocForDecl DocName  -- ^ documentation
-               -> ( LaTeX             -- ^ first-line (no-argument docs only)
-                  , LaTeX             -- ^ first-line (argument docs only)
-                  , LaTeX             -- ^ type prefix (argument docs only)
+               -> ( LaTeX             --   first-line (no-argument docs only)
+                  , LaTeX             --   first-line (argument docs only)
+                  , LaTeX             --   type prefix (argument docs only)
                   )
                -> Bool                -- ^ unicode
                -> LaTeX
--
2.23.0


code:
This patch is taken and adapted from upstream.  It landed shortly after
the release of 0.31.2, and fixes eleven tests.  The patch has been
lightly adapted to apply to the release tarball, but the commit message
was left untouched, so it refers to some changes not included in the
patch.

From a8d9362d4b686074f698c04c20beea88587511a1 Mon Sep 17 00:00:00 2001
From: quasicomputational <quasicomputational@gmail.com>
Date: Sat, 1 Jun 2019 15:11:31 +0100
Subject: [PATCH] Make CI green (#345)

* AppVeyor workaround for TMP issue

https://github.com/commercialhaskell/stack/issues/3944

* Bump resolver to nightly-2018-12-12.

This has the primary benefit of moving to GHC 8.6.3 and should fix
AppVeyor.

* Add clock 0.8 as an extra-dep.

* Adapt expected output to aeson 1.4.3.0.
---
 appveyor.yml                            |  3 +++
 hpack.cabal                             | 10 +++++-----
 package.yaml                            |  2 +-
 stack.yaml                              |  5 +++--
 test/Data/Aeson/Config/FromValueSpec.hs |  2 +-
 test/Data/Aeson/Config/TypesSpec.hs     |  2 +-
 test/EndToEndSpec.hs                    |  8 ++++----
 test/Hpack/ConfigSpec.hs                |  2 +-
 test/Hpack/Syntax/DefaultsSpec.hs       |  2 +-
 test/Hpack/Syntax/DependenciesSpec.hs   |  4 ++--
 10 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/hpack.cabal b/hpack.cabal
index fedb9a8..4db3014 100644
--- a/hpack.cabal
+++ b/hpack.cabal
@@ -1,10 +1,10 @@
 cabal-version: 1.12

--- This file has been generated from package.yaml by hpack version 0.31.0.
+-- This file has been generated from package.yaml by hpack version 0.31.2.
 --
 -- see: https://github.com/sol/hpack
 --
--- hash: 3d060180293c32b8d0c25b710d0f419e96a6cc6ec3f95ac5e70bb77f44cbafc3
+-- hash: bd5dd178c7e9f7f7a3456d79b592ea336c41ef43c9892354c001f06659e8b901

 name:           hpack
 version:        0.31.2
@@ -31,7 +31,7 @@ library
   build-depends:
       Cabal >=2.2
     , Glob >=0.9.0
-    , aeson >=1.2.1.0
+    , aeson >=1.4.3.0
     , base >=4.9 && <5
     , bifunctors
     , bytestring
@@ -87,7 +87,7 @@ executable hpack
   build-depends:
       Cabal >=2.2
     , Glob >=0.9.0
-    , aeson >=1.2.1.0
+    , aeson >=1.4.3.0
     , base >=4.9 && <5
     , bifunctors
     , bytestring
@@ -125,7 +125,7 @@ test-suite spec
     , Glob >=0.9.0
     , HUnit >=1.6.0.0
     , QuickCheck
-    , aeson >=1.2.1.0
+    , aeson >=1.4.3.0
     , base >=4.9 && <5
     , bifunctors
     , bytestring
diff --git a/test/Data/Aeson/Config/FromValueSpec.hs b/test/Data/Aeson/Config/FromValueSpec.hs
index 33de8b7..06b3eb9 100644
--- a/test/Data/Aeson/Config/FromValueSpec.hs
+++ b/test/Data/Aeson/Config/FromValueSpec.hs
@@ -85,7 +85,7 @@ spec = do
         [yaml|
         name: "Joe"
         age: "23"
-        |] `shouldDecodeTo` left "Error while parsing $.age - expected Int, encountered String"
+        |] `shouldDecodeTo` left "Error while parsing $.age - parsing Int failed, expected Number, but encountered String"

     context "with (,)" $ do
       it "captures unrecognized fields" $ do
diff --git a/test/Data/Aeson/Config/TypesSpec.hs b/test/Data/Aeson/Config/TypesSpec.hs
index c954534..472aa42 100644
--- a/test/Data/Aeson/Config/TypesSpec.hs
+++ b/test/Data/Aeson/Config/TypesSpec.hs
@@ -13,7 +13,7 @@ spec = do
     context "List" $ do
       let
         parseError :: String -> Result (List Int)
-        parseError prefix = Left (prefix ++ " - expected Int, encountered String")
+        parseError prefix = Left (prefix ++ " - parsing Int failed, expected Number, but encountered String")

       context "when parsing single values" $ do
         it "returns the value in a singleton list" $ do
diff --git a/test/EndToEndSpec.hs b/test/EndToEndSpec.hs
index 283c72c..46389ea 100644
--- a/test/EndToEndSpec.hs
+++ b/test/EndToEndSpec.hs
@@ -285,7 +285,7 @@ spec = around_ (inTempDirectoryNamed "foo") $ do
           path: defaults.yaml
           ref: "2017"
         library: {}
-        |] `shouldFailWith` (file ++ ": Error while parsing $ - expected Object, encountered Array")
+        |] `shouldFailWith` (file ++ ": Error while parsing $ - expected Object, but encountered Array")

       it "warns on unknown fields" $ do
         let file = joinPath ["defaults", "sol", "hpack-template", "2017", "defaults.yaml"]
@@ -340,7 +340,7 @@ spec = around_ (inTempDirectoryNamed "foo") $ do
       it "rejects other values" $ do
         [i|
         version: {}
-        |] `shouldFailWith` "package.yaml: Error while parsing $.version - expected Number or String, encountered Object"
+        |] `shouldFailWith` "package.yaml: Error while parsing $.version - expected Number or String, but encountered Object"

     describe "license" $ do
       it "accepts cabal-style licenses" $ do
@@ -1363,14 +1363,14 @@ spec = around_ (inTempDirectoryNamed "foo") $ do
             then:
               dependencies: Win32
             else: null
-          |] `shouldFailWith` "package.yaml: Error while parsing $.when.else - expected Object, encountered Null"
+          |] `shouldFailWith` "package.yaml: Error while parsing $.when.else - expected Object, but encountered Null"

         it "rejects invalid conditionals" $ do
           [i|
             dependencies:
               - foo
               - 23
-          |] `shouldFailWith` "package.yaml: Error while parsing $.dependencies[1] - expected Object or String, encountered Number"
+          |] `shouldFailWith` "package.yaml: Error while parsing $.dependencies[1] - expected Object or String, but encountered Number"

         it "warns on unknown fields" $ do
           [i|
diff --git a/test/Hpack/ConfigSpec.hs b/test/Hpack/ConfigSpec.hs
index 9f4b279..69cbea1 100644
--- a/test/Hpack/ConfigSpec.hs
+++ b/test/Hpack/ConfigSpec.hs
@@ -675,7 +675,7 @@ spec = do
       it "rejects other values" $ do
         [yaml|
         23
-        |] `shouldDecodeTo` (Left "Error while parsing $ - expected Boolean or String, encountered Number" :: Result Cond)
+        |] `shouldDecodeTo` (Left "Error while parsing $ - expected Boolean or String, but encountered Number" :: Result Cond)

   describe "formatOrList" $ do
     it "formats a singleton list" $ do
diff --git a/test/Hpack/Syntax/DefaultsSpec.hs b/test/Hpack/Syntax/DefaultsSpec.hs
index 5875413..5438b7a 100644
--- a/test/Hpack/Syntax/DefaultsSpec.hs
+++ b/test/Hpack/Syntax/DefaultsSpec.hs
@@ -151,4 +151,4 @@ spec = do
         it "fails" $ do
           [yaml|
           10
-          |] `shouldDecodeTo` left "Error while parsing $ - expected Object or String, encountered Number"
+          |] `shouldDecodeTo` left "Error while parsing $ - expected Object or String, but encountered Number"
diff --git a/test/Hpack/Syntax/DependenciesSpec.hs b/test/Hpack/Syntax/DependenciesSpec.hs
index 1a83732..d95044f 100644
--- a/test/Hpack/Syntax/DependenciesSpec.hs
+++ b/test/Hpack/Syntax/DependenciesSpec.hs
@@ -125,7 +125,7 @@ spec = do
         it "rejects invalid values" $ do
           [yaml|
             hpack: []
-          |] `shouldDecodeTo` left "Error while parsing $.hpack - expected Null, Object, Number, or String, encountered Array"
+          |] `shouldDecodeTo` left "Error while parsing $.hpack - expected Null, Object, Number, or String, but encountered Array"

         context "when the constraint is a Number" $ do
           it "accepts 1" $ do
@@ -213,7 +213,7 @@ spec = do
               [yaml|
                 foo:
                   version: {}
-              |] `shouldDecodeTo` left "Error while parsing $.foo.version - expected Null, Number, or String, encountered Object"
+              |] `shouldDecodeTo` left "Error while parsing $.foo.version - expected Null, Number, or String, but encountered Object"

             it "accepts a string" $ do
               [yaml|
--
2.23.0


code:
This patch fixes the test suite to allow any order when listing the
members of a JSON object.  Aeson (being true to the JSON specification)
does not specify an order for objects.  In practice, the order depends
on your processor architecture.

See <https://github.com/bos/aeson/issues/568> for a discussion resulting
in a similar patch fixing the Aeson tests.

See <https://github.com/fosskers/microlens-aeson/issues/1> for the
upstream bug report.

diff -ruN a/test/Test.hs b/test/Test.hs
--- a/test/Test.hs	2018-12-31 15:10:50.000000000 -0500
+++ b/test/Test.hs	2019-11-08 01:34:07.419706831 -0500
@@ -48,8 +48,10 @@
     , testCase "" $ ("{\"a\": {}, \"b\": null}" ^? key (T.pack "b") . _Object) @?= Nothing
     , testCase "" $ ("{\"a\": 100, \"b\": 200}" ^? key (T.pack "a")) @?= Just (Number 100.0)
     , testCase "" $ ("[1,2,3]" ^? key (T.pack "a")) @?= Nothing
-    , testCase "" $ ("{\"a\": 4, \"b\": 7}" ^.. members) @?= [Number 4.0,Number 7.0]
-    , testCase "" $ ("{\"a\": 4, \"b\": 7}" & members . _Number %~ (* 10)) @?= "{\"a\":40,\"b\":70}"
+    , testCase "" $ assertBool "" (let x = ("{\"a\": 4, \"b\": 7}" ^.. members)
+                                   in x == [Number 4.0,Number 7.0] || x == [Number 7.0,Number 4.0])
+    , testCase "" $ assertBool "" (let x = ("{\"a\": 4, \"b\": 7}" & members . _Number %~ (* 10))
+                                   in x == "{\"a\":40,\"b\":70}" || x == "{\"b\":70,\"a\":40}")
     , testCase "" $ ("[1,2,3]" ^? nth 1) @?= Just (Number 2.0)
     , testCase "" $ ("{\"a\": 100, \"b\": 200}" ^? nth 1) @?= Nothing
     , testCase "" $ ("[1,2,3]" & nth 1 .~ Number 20) @?= "[1,20,3]"


code:
This patch is taken from upstream.  It fixes a test to work with GHC 8.6.
The paths have been slightly altered to work with the release tarball.

See <https://github.com/simonmar/monad-par/issues/66>.

From e20f81c8060208e4fb038e8f0e0668b41d72a6fb Mon Sep 17 00:00:00 2001
From: Clint Adams <clint@debian.org>
Date: Sat, 31 Aug 2019 14:12:34 -0400
Subject: [PATCH] Use a case statement instead of pattern-matching in
 case_test_diamond

This avoids the need for a MonadFail instance.  Closes #66
---
 monad-par/tests/ParTests_shared.hs | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tests/ParTests_shared.hs b/tests/ParTests_shared.hs
index 31f438d..b2de50c 100644
--- a/tests/ParTests_shared.hs
+++ b/tests/ParTests_shared.hs
@@ -109,12 +109,15 @@ case_test_diamond :: Assertion
 case_test_diamond = 9 @=? (m :: Int)
  where
   m = runPar $ do
-      [a,b,c,d] <- sequence [new,new,new,new]
-      fork $ do x <- get a; put b (x+1)
-      fork $ do x <- get a; put c (x+2)
-      fork $ do x <- get b; y <- get c; put d (x+y)
-      fork $ do put a 3
-      get d
+      abcd <- sequence [new,new,new,new]
+      case abcd of
+          [a,b,c,d] -> do
+              fork $ do x <- get a; put b (x+1)
+              fork $ do x <- get a; put c (x+2)
+              fork $ do x <- get b; y <- get c; put d (x+y)
+              fork $ do put a 3
+              get d
+          _ -> error "Oops"

 -- | Violate IVar single-assignment:
 --
--
2.23.0


code:
This patch is taken from upstream.  It fixes two HTML tests that are broken
due to using a Skylighting version greater than or equal to 0.8.2.

From 968d2046a3cb6db661673be580660ac402753c34 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Sun, 14 Jul 2019 10:48:14 -0700
Subject: [PATCH] Update test for new skylighting.

---
 test/lhs-test.html     | 13 ++++++-------
 test/lhs-test.html+lhs | 13 ++++++-------
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/test/lhs-test.html b/test/lhs-test.html
index 6685555f4..446dd3d95 100644
--- a/test/lhs-test.html
+++ b/test/lhs-test.html
@@ -12,19 +12,18 @@
       div.column{display: inline-block; vertical-align: top; width: 50%;}
   </style>
   <style>
-code.sourceCode > span { display: inline-block; line-height: 1.25; }
+pre > code.sourceCode { white-space: pre; position: relative; }
+pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
+pre > code.sourceCode > span:empty { height: 1.2em; }
 code.sourceCode > span { color: inherit; text-decoration: inherit; }
-code.sourceCode > span:empty { height: 1.2em; }
-.sourceCode { overflow: visible; }
-code.sourceCode { white-space: pre; position: relative; }
 div.sourceCode { margin: 1em 0; }
 pre.sourceCode { margin: 0; }
 @media screen {
 div.sourceCode { overflow: auto; }
 }
 @media print {
-code.sourceCode { white-space: pre-wrap; }
-code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
+pre > code.sourceCode { white-space: pre-wrap; }
+pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
 }
 pre.numberSource code
   { counter-reset: source-line 0; }
@@ -44,7 +43,7 @@ pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-le
 div.sourceCode
   {   }
 @media screen {
-code.sourceCode > span > a:first-child::before { text-decoration: underline; }
+pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
 }
 code span.al { color: #ff0000; font-weight: bold; } /* Alert */
 code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
diff --git a/test/lhs-test.html+lhs b/test/lhs-test.html+lhs
index e57dfc105..a5cdb0245 100644
--- a/test/lhs-test.html+lhs
+++ b/test/lhs-test.html+lhs
@@ -12,19 +12,18 @@
       div.column{display: inline-block; vertical-align: top; width: 50%;}
   </style>
   <style>
-code.sourceCode > span { display: inline-block; line-height: 1.25; }
+pre > code.sourceCode { white-space: pre; position: relative; }
+pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
+pre > code.sourceCode > span:empty { height: 1.2em; }
 code.sourceCode > span { color: inherit; text-decoration: inherit; }
-code.sourceCode > span:empty { height: 1.2em; }
-.sourceCode { overflow: visible; }
-code.sourceCode { white-space: pre; position: relative; }
 div.sourceCode { margin: 1em 0; }
 pre.sourceCode { margin: 0; }
 @media screen {
 div.sourceCode { overflow: auto; }
 }
 @media print {
-code.sourceCode { white-space: pre-wrap; }
-code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
+pre > code.sourceCode { white-space: pre-wrap; }
+pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
 }
 pre.numberSource code
   { counter-reset: source-line 0; }
@@ -44,7 +43,7 @@ pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-le
 div.sourceCode
   {   }
 @media screen {
-code.sourceCode > span > a:first-child::before { text-decoration: underline; }
+pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
 }
 code span.al { color: #ff0000; font-weight: bold; } /* Alert */
 code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
--
2.23.0


code:
This patch is taken from upstream.  It fixes a LaTeX test that is broken due
to using a Skylighting version greater than or equal to 0.8.1.1.

From 2cd1c7b30f200d18f1f1bdef1671369e1ad303ed Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Thu, 13 Jun 2019 19:33:52 -0700
Subject: [PATCH] Update test for skylighting 0.8.1.1.

---
 test/lhs-test.latex | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/lhs-test.latex b/test/lhs-test.latex
index 0442db5ca..a456995a3 100644
--- a/test/lhs-test.latex
+++ b/test/lhs-test.latex
@@ -94,9 +94,9 @@ return a single value:

 \begin{Shaded}
 \begin{Highlighting}[]
-\OtherTok{unsplit ::}\NormalTok{ (}\DataTypeTok{Arrow}\NormalTok{ a) }\OtherTok{=>}\NormalTok{ (b }\OtherTok{->}\NormalTok{ c }\OtherTok{->}\NormalTok{ d) }\OtherTok{->}\NormalTok{ a (b, c) d}
+\OtherTok{unsplit ::}\NormalTok{ (}\DataTypeTok{Arrow}\NormalTok{ a) }\OtherTok{=>}\NormalTok{ (b }\OtherTok{{-}>}\NormalTok{ c }\OtherTok{{-}>}\NormalTok{ d) }\OtherTok{{-}>}\NormalTok{ a (b, c) d}
 \NormalTok{unsplit }\OtherTok{=}\NormalTok{ arr }\OperatorTok{.} \FunctionTok{uncurry}
-          \CommentTok{-- arr (\textbackslash{}op (x,y) -> x `op` y)}
+          \CommentTok{{-}{-} arr (\textbackslash{}op (x,y) {-}> x \textasciigrave{}op\textasciigrave{} y)}
 \end{Highlighting}
 \end{Shaded}

--
2.23.0


code:
Do not attempt to dlopen PIE objects, which was disallowed with glibc 2.30.

https://gitlab.haskell.org/ghc/ghc/issues/17952
https://sourceware.org/bugzilla/show_bug.cgi?id=24323

Patch submitted upstream:
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2947

diff --git a/testsuite/tests/dynlibs/Makefile b/testsuite/tests/dynlibs/Makefile
--- a/testsuite/tests/dynlibs/Makefile
+++ b/testsuite/tests/dynlibs/Makefile
@@ -60,6 +60,4 @@ T5373:
 .PHONY: T13702
 T13702:
 	'$(TEST_HC)' -v0 -dynamic -rdynamic -fPIC -pie T13702.hs
-	'$(TEST_HC)' -v0 -dynamic T13702a.hs
-	./T13702  # first make sure executable itself works
-	./T13702a # then try dynamically loading it as library
+	./T13702
diff --git a/testsuite/tests/dynlibs/T13702.hs b/testsuite/tests/dynlibs/T13702.hs
--- a/testsuite/tests/dynlibs/T13702.hs
+++ b/testsuite/tests/dynlibs/T13702.hs
@@ -2,8 +2,3 @@

 main :: IO ()
 main = putStrLn "hello world"
-
-foreign export ccall "hello" hello :: IO ()
-
-hello :: IO ()
-hello = putStrLn "hello world again"
diff --git a/testsuite/tests/dynlibs/T13702.stdout b/testsuite/tests/dynlibs/T13702.stdout
--- a/testsuite/tests/dynlibs/T13702.stdout
+++ b/testsuite/tests/dynlibs/T13702.stdout
@@ -1,2 +1 @@
 hello world
-hello world again
diff --git a/testsuite/tests/dynlibs/T13702a.hs b/testsuite/tests/dynlibs/T13702a.hs
deleted file mode 100644
--- a/testsuite/tests/dynlibs/T13702a.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
-
-import Foreign
-import System.Posix.DynamicLinker
-
-main :: IO ()
-main = do
-    dl <- dlopen "./T13702" [RTLD_NOW]
-    funptr <- dlsym dl "hello" :: IO (FunPtr (IO ()))
-    mkAction funptr
-
-foreign import ccall "dynamic" mkAction :: FunPtr (IO ()) -> IO ()


code:
Fix CVE-2020-15900.

https://cve.circl.lu/cve/CVE-2020-15900
https://artifex.com/security-advisories/CVE-2020-15900

Taken from upstream:
https://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=5d499272b95a6b890a1397e11d20937de000d31b

diff --git a/psi/zstring.c b/psi/zstring.c
--- a/psi/zstring.c
+++ b/psi/zstring.c
@@ -142,13 +142,18 @@ search_impl(i_ctx_t *i_ctx_p, bool forward)
     return 0;
 found:
     op->tas.type_attrs = op1->tas.type_attrs;
-    op->value.bytes = ptr;
-    r_set_size(op, size);
+    op->value.bytes = ptr;				/* match */
+    op->tas.rsize = size;				/* match */
     push(2);
-    op[-1] = *op1;
-    r_set_size(op - 1, ptr - op[-1].value.bytes);
-    op1->value.bytes = ptr + size;
-    r_set_size(op1, count + (!forward ? (size - 1) : 0));
+    op[-1] = *op1;					/* pre */
+    op[-3].value.bytes = ptr + size;			/* post */
+    if (forward) {
+        op[-1].tas.rsize = ptr - op[-1].value.bytes;	/* pre */
+        op[-3].tas.rsize = count;			/* post */
+    } else {
+        op[-1].tas.rsize = count;			/* pre */
+        op[-3].tas.rsize -= count + size;		/* post */
+    }
     make_true(op);
     return 0;
 }


code:
Fix build with FreeType 2.10.3 and newer.

Taken from upstream:
https://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=41ef9a0bc36b9db7115fbe9623f989bfb47bbade

diff --git a/base/fapi_ft.c b/base/fapi_ft.c
--- a/base/fapi_ft.c
+++ b/base/fapi_ft.c
@@ -125,7 +125,7 @@ static void
 delete_inc_int_info(gs_fapi_server * a_server,
                     FT_IncrementalRec * a_inc_int_info);

-FT_CALLBACK_DEF(void *)
+static void *
 FF_alloc(FT_Memory memory, long size)
 {
     gs_memory_t *mem = (gs_memory_t *) memory->user;
@@ -133,7 +133,7 @@ FF_alloc(FT_Memory memory, long size)
     return (gs_malloc(mem, size, 1, "FF_alloc"));
 }

-FT_CALLBACK_DEF(void *)
+static void *
     FF_realloc(FT_Memory memory, long cur_size, long new_size, void *block)
 {
     gs_memory_t *mem = (gs_memory_t *) memory->user;
@@ -153,7 +153,7 @@ FT_CALLBACK_DEF(void *)
     return (tmp);
 }

-FT_CALLBACK_DEF(void)
+static void
     FF_free(FT_Memory memory, void *block)
 {
     gs_memory_t *mem = (gs_memory_t *) memory->user;


code:
This patch makes emission of /CreationDate and /ModDate headers optional.

If the environment variable GS_GENERATE_UUIDS is set to "0" or "no", it will
not write out the "/ID" field (if that's permissible).

Upstream does not want to do this.

See: https://bugs.ghostscript.com/show_bug.cgi?id=698208
diff --git a/orig/gnu-ghostscript-9.14.0/devices/vector/gdevpdf.c b/bb/gnu-ghostscript-9.14.0/devices/vector/gdevpdf.c
index 0fb067e..b342e2c 100644
--- orig/gnu-ghostscript-9.14.0/devices/vector/gdevpdf.c
+++ gnu-ghostscript-9.14.0/devices/vector/gdevpdf.c
@@ -305,6 +305,9 @@ pdf_initialize_ids(gx_device_pdf * pdev)
      * date and time, rather than (for example) %%CreationDate from the
      * PostScript file.  We think this is wrong, but we do the same.
      */
+    if (!getenv("GS_GENERATE_UUIDS") ||
+        (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 &&
+         strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))
     {
         struct tm tms;
         time_t t;


code:
This patch makes the "/ID" field optional.

If the environment variable GS_GENERATE_UUIDS is set to "0" or "no", it will
not write out the "/ID" field (if that's permissible).

Upstream does not want to do this.

See: https://bugs.ghostscript.com/show_bug.cgi?id=698208
diff -ur orig/gnu-ghostscript-9.14.0/devices/vector/gdevpdf.c gnu-ghostscript-9.14.0/devices/vector/gdevpdf.c
--- orig/gnu-ghostscript-9.14.0/devices/vector/gdevpdf.c	2017-07-09 23:30:28.960479189 +0200
+++ gnu-ghostscript-9.14.0/devices/vector/gdevpdf.c	2017-07-09 23:34:34.306524488 +0200
@@ -1810,8 +1810,11 @@
      * +1 for the linearisation dict and +1 for the primary hint stream.
      */
     linear_params->FirsttrailerOffset = gp_ftell(linear_params->Lin_File.file);
-    gs_sprintf(LDict, "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R/ID[%s%s]/Prev %d>>\nstartxref\r\n0\n%%%%EOF\n        \n",
-        linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber, fileID, fileID, 0);
+    gs_sprintf(LDict, "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R",
+        linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber);
+    if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 && strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) /* ID is mandatory when encrypting */
+        gs_sprintf(LDict, "/ID[%s%s]", fileID, fileID);
+    gs_sprintf(LDict, "/Prev %d>>\nstartxref\r\n0\n%%%%EOF\n        \n", 0);
     gp_fwrite(LDict, strlen(LDict), 1, linear_params->Lin_File.file);

     /* Write document catalog (Part 4) */
@@ -2346,8 +2349,11 @@
     if (code != 0)
         return_error(gs_error_ioerror);

-    gs_sprintf(LDict, "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R/ID[%s%s]/Prev %"PRId64">>\nstartxref\r\n0\n%%%%EOF\n",
-        linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber, fileID, fileID, mainxref);
+    gs_sprintf(LDict, "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R",
+        linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber);
+    if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 || strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) /* ID is mandatory when encrypting */
+        gs_sprintf(LDict, "/ID[%s%s]", fileID, fileID);
+    gs_sprintf(LDict, "/Prev %"PRId64">>\nstartxref\r\n0\n%%%%EOF\n", mainxref);
     gp_fwrite(LDict, strlen(LDict), 1, linear_params->sfile);

     code = gp_fseek(linear_params->sfile, pdev->ResourceUsage[HintStreamObj].LinearisedOffset, SEEK_SET);
@@ -3012,10 +3018,12 @@
             stream_puts(s, "trailer\n");
             pprintld3(s, "<< /Size %ld /Root %ld 0 R /Info %ld 0 R\n",
                   pdev->next_id, Catalog_id, Info_id);
-            stream_puts(s, "/ID [");
-            psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
-            psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
-            stream_puts(s, "]\n");
+            if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 || strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) { /* ID is mandatory when encrypting */
+                stream_puts(s, "/ID [");
+                psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
+                psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
+                stream_puts(s, "]\n");
+            }
             if (pdev->OwnerPassword.size > 0) {
                 pprintld1(s, "/Encrypt %ld 0 R ", Encrypt_id);
             }


code:
This patch makes the UUIDs in the XMP header optional, depending on the
setting of the environment variable GS_GENERATE_UUIDS.

If the environment variable GS_GENERATE_UUIDS is set to "0" or "no", it will
not write out the Document UUID field and also will write the Instance ID
field value as "".

Upstream does not want to do this.

See: https://bugs.ghostscript.com/show_bug.cgi?id=698208
diff -ur orig/gnu-ghostscript-9.14.0/devices/vector/gdevpdfe.c aa/gnu-ghostscript-9.14.0/devices/vector/gdevpdfe.c
--- orig/gnu-ghostscript-9.14.0/devices/vector/gdevpdfe.c	2017-07-09 23:30:28.960479189 +0200
+++ gnu-ghostscript-9.14.0/devices/vector/gdevpdfe.c	2017-07-10 01:04:12.252478276 +0200
@@ -620,7 +620,7 @@
         return code;

     /* PDF/A XMP reference recommends setting UUID to empty. If not empty must be a URI */
-    if (pdev->PDFA != 0)
+    if (pdev->PDFA != 0 || (getenv("GS_GENERATE_UUIDS") && (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") == 0 || strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") == 0)))
         instance_uuid[0] = 0x00;

     cre_date_time_len = pdf_get_docinfo_item(pdev, "/CreationDate", cre_date_time, sizeof(cre_date_time));
@@ -720,14 +720,17 @@
             pdf_xml_tag_close(s, "rdf:Description");
             pdf_xml_newline(s);

-            pdf_xml_tag_open_beg(s, "rdf:Description");
-            pdf_xml_copy(s, " rdf:about=\"\"");
-            pdf_xml_attribute_name(s, "xmlns:xapMM");
-            pdf_xml_attribute_value(s, "http://ns.adobe.com/xap/1.0/mm/");
-            pdf_xml_attribute_name(s, "xapMM:DocumentID");
-            pdf_xml_attribute_value(s, document_uuid);
-            pdf_xml_tag_end_empty(s);
-            pdf_xml_newline(s);
+            if (!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 && strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))
+            {
+                pdf_xml_tag_open_beg(s, "rdf:Description");
+                pdf_xml_copy(s, " rdf:about=\"\"");
+                pdf_xml_attribute_name(s, "xmlns:xapMM");
+                pdf_xml_attribute_value(s, "http://ns.adobe.com/xap/1.0/mm/");
+                pdf_xml_attribute_name(s, "xapMM:DocumentID");
+                pdf_xml_attribute_value(s, document_uuid);
+                pdf_xml_tag_end_empty(s);
+                pdf_xml_newline(s);
+            }

             pdf_xml_tag_open_beg(s, "rdf:Description");
             pdf_xml_copy(s, " rdf:about=\"\"");


code:
From f4adc1f52d777cea3331b4acae0c3bdec4d0eb70 Mon Sep 17 00:00:00 2001
From: Paper <paper@tilde.institute>
Date: Fri, 12 Mar 2021 21:10:34 +0000
Subject: [PATCH] fix login by removing everything after # from URL

---
 giara/__main__.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/giara/__main__.py b/giara/__main__.py
index 10b9ae2..d235332 100644
--- a/giara/__main__.py
+++ b/giara/__main__.py
@@ -53,8 +53,9 @@ class GApplication(Gtk.Application):
     def open(self, app, files, *args):
         target = files[0].get_uri()
         print(target)
+        code = target.split('=')[-1].split('#')[0]
         get_authorized_client(
-            reddit=self._unauth_reddit, code=target.split('=')[-1]
+            reddit=self._unauth_reddit, code=code
         )
         self.continue_activate(self._unauth_reddit)

--
GitLab


code:
Backport of:

From 0f384c88a241bbbd884487b1c40b7b75f1e638d3 Mon Sep 17 00:00:00 2001
From: Krzesimir Nowak <qdlacz@gmail.com>
Date: Wed, 10 Feb 2021 23:51:07 +0100
Subject: [PATCH] gbytearray: Do not accept too large byte arrays

GByteArray uses guint for storing the length of the byte array, but it
also has a constructor (g_byte_array_new_take) that takes length as a
gsize. gsize may be larger than guint (64 bits for gsize vs 32 bits
for guint). It is possible to call the function with a value greater
than G_MAXUINT, which will result in silent length truncation. This
may happen as a result of unreffing GBytes into GByteArray, so rather
be loud about it.

(Test case tweaked by Philip Withnall.)

(Backport 2.66: Add #include gstrfuncsprivate.h in the test case for
`g_memdup2()`.)
---
 glib/garray.c      |  6 ++++++
 glib/gbytes.c      |  4 ++++
 glib/tests/bytes.c | 35 ++++++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/glib/garray.c b/glib/garray.c
index 942e74c9f..fb1a42aaf 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -2013,6 +2013,10 @@ g_byte_array_new (void)
  * Create byte array containing the data. The data will be owned by the array
  * and will be freed with g_free(), i.e. it could be allocated using g_strdup().
  *
+ * Do not use it if @len is greater than %G_MAXUINT. #GByteArray
+ * stores the length of its data in #guint, which may be shorter than
+ * #gsize.
+ *
  * Since: 2.32
  *
  * Returns: (transfer full): a new #GByteArray
@@ -2024,6 +2028,8 @@ g_byte_array_new_take (guint8 *data,
   GByteArray *array;
   GRealArray *real;

+  g_return_val_if_fail (len <= G_MAXUINT, NULL);
+
   array = g_byte_array_new ();
   real = (GRealArray *)array;
   g_assert (real->data == NULL);
diff --git a/glib/gbytes.c b/glib/gbytes.c
index 7b72886e5..d56abe6c3 100644
--- a/glib/gbytes.c
+++ b/glib/gbytes.c
@@ -519,6 +519,10 @@ g_bytes_unref_to_data (GBytes *bytes,
  * g_bytes_new(), g_bytes_new_take() or g_byte_array_free_to_bytes(). In all
  * other cases the data is copied.
  *
+ * Do not use it if @bytes contains more than %G_MAXUINT
+ * bytes. #GByteArray stores the length of its data in #guint, which
+ * may be shorter than #gsize, that @bytes is using.
+ *
  * Returns: (transfer full): a new mutable #GByteArray containing the same byte data
  *
  * Since: 2.32
diff --git a/glib/tests/bytes.c b/glib/tests/bytes.c
index 5ea5c2b35..15a6aaad6 100644
--- a/glib/tests/bytes.c
+++ b/glib/tests/bytes.c
@@ -10,12 +10,12 @@
  */

 #undef G_DISABLE_ASSERT
-#undef G_LOG_DOMAIN

 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "glib.h"
+#include "glib/gstrfuncsprivate.h"

 /* Keep in sync with glib/gbytes.c */
 struct _GBytes
@@ -333,6 +333,38 @@ test_to_array_transferred (void)
   g_byte_array_unref (array);
 }

+static void
+test_to_array_transferred_oversize (void)
+{
+  g_test_message ("g_bytes_unref_to_array() can only take GBytes up to "
+                  "G_MAXUINT in length; test that longer ones are rejected");
+
+  if (sizeof (guint) >= sizeof (gsize))
+    {
+      g_test_skip ("Skipping test as guint is not smaller than gsize");
+    }
+  else if (g_test_undefined ())
+    {
+      GByteArray *array = NULL;
+      GBytes *bytes = NULL;
+      gpointer data = g_memdup2 (NYAN, N_NYAN);
+      gsize len = ((gsize) G_MAXUINT) + 1;
+
+      bytes = g_bytes_new_take (data, len);
+      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                             "g_byte_array_new_take: assertion 'len <= G_MAXUINT' failed");
+      array = g_bytes_unref_to_array (g_steal_pointer (&bytes));
+      g_test_assert_expected_messages ();
+      g_assert_null (array);
+
+      g_free (data);
+    }
+  else
+    {
+      g_test_skip ("Skipping test as testing undefined behaviour is disabled");
+    }
+}
+
 static void
 test_to_array_two_refs (void)
 {
@@ -410,6 +442,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/bytes/to-array/transfered", test_to_array_transferred);
   g_test_add_func ("/bytes/to-array/two-refs", test_to_array_two_refs);
   g_test_add_func ("/bytes/to-array/non-malloc", test_to_array_non_malloc);
+  g_test_add_func ("/bytes/to-array/transferred/oversize", test_to_array_transferred_oversize);
   g_test_add_func ("/bytes/null", test_null);

   return g_test_run ();
--
2.30.1


code:
Backport of:

From 5e5f75a77e399c638be66d74e5daa8caeb433e00 Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Thu, 4 Feb 2021 13:30:52 +0000
Subject: [PATCH 01/11] gstrfuncs: Add internal g_memdup2() function
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This will replace the existing `g_memdup()` function for use within
GLib. It has an unavoidable security flaw of taking its `byte_size`
argument as a `guint` rather than as a `gsize`. Most callers will
expect it to be a `gsize`, and may pass in large values which could
silently be truncated, resulting in an undersize allocation compared
to what the caller expects.

This could lead to a classic buffer overflow vulnerability for many
callers of `g_memdup()`.

`g_memdup2()`, in comparison, takes its `byte_size` as a `gsize`.

Spotted by Kevin Backhouse of GHSL.

In GLib 2.68, `g_memdup2()` will be a new public API. In this version
for backport to older stable releases, it’s a new `static inline` API
in a private header, so that use of `g_memdup()` within GLib can be
fixed without adding a new API in a stable release series.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: GHSL-2021-045
Helps: #2319
---
 docs/reference/glib/meson.build |  1 +
 glib/gstrfuncsprivate.h         | 55 +++++++++++++++++++++++++++++++++
 glib/meson.build                |  1 +
 glib/tests/strfuncs.c           | 23 ++++++++++++++
 4 files changed, 80 insertions(+)
 create mode 100644 glib/gstrfuncsprivate.h

diff --git a/docs/reference/glib/meson.build b/docs/reference/glib/meson.build
index bba7649f0..ee39f6d04 100644
--- a/docs/reference/glib/meson.build
+++ b/docs/reference/glib/meson.build
@@ -22,6 +22,7 @@ if get_option('gtk_doc')
     'gprintfint.h',
     'gmirroringtable.h',
     'gscripttable.h',
+    'gstrfuncsprivate.h',
     'glib-mirroring-tab',
     'gnulib',
     'pcre',
diff --git a/glib/gstrfuncsprivate.h b/glib/gstrfuncsprivate.h
new file mode 100644
index 000000000..85c88328a
--- /dev/null
+++ b/glib/gstrfuncsprivate.h
@@ -0,0 +1,55 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+/*
+ * g_memdup2:
+ * @mem: (nullable): the memory to copy.
+ * @byte_size: the number of bytes to copy.
+ *
+ * Allocates @byte_size bytes of memory, and copies @byte_size bytes into it
+ * from @mem. If @mem is %NULL it returns %NULL.
+ *
+ * This replaces g_memdup(), which was prone to integer overflows when
+ * converting the argument from a #gsize to a #guint.
+ *
+ * This static inline version is a backport of the new public API from
+ * GLib 2.68, kept internal to GLib for backport to older stable releases.
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2319.
+ *
+ * Returns: (nullable): a pointer to the newly-allocated copy of the memory,
+ *    or %NULL if @mem is %NULL.
+ * Since: 2.68
+ */
+static inline gpointer
+g_memdup2 (gconstpointer mem,
+           gsize         byte_size)
+{
+  gpointer new_mem;
+
+  if (mem && byte_size != 0)
+    {
+      new_mem = g_malloc (byte_size);
+      memcpy (new_mem, mem, byte_size);
+    }
+  else
+    new_mem = NULL;
+
+  return new_mem;
+}
diff --git a/glib/meson.build b/glib/meson.build
index aaf5f00f5..5a6eea397 100644
--- a/glib/meson.build
+++ b/glib/meson.build
@@ -268,6 +268,7 @@ glib_sources = files(
   'gslist.c',
   'gstdio.c',
   'gstrfuncs.c',
+  'gstrfuncsprivate.h',
   'gstring.c',
   'gstringchunk.c',
   'gtestutils.c',
diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c
index e1f9619c7..d968afff9 100644
--- a/glib/tests/strfuncs.c
+++ b/glib/tests/strfuncs.c
@@ -32,6 +32,8 @@
 #include <string.h>
 #include "glib.h"

+#include "gstrfuncsprivate.h"
+
 #if defined (_MSC_VER) && (_MSC_VER <= 1800)
 #define isnan(x) _isnan(x)

@@ -219,6 +221,26 @@ test_memdup (void)
   g_free (str_dup);
 }

+/* Testing g_memdup2() function with various positive and negative cases */
+static void
+test_memdup2 (void)
+{
+  gchar *str_dup = NULL;
+  const gchar *str = "The quick brown fox jumps over the lazy dog";
+
+  /* Testing negative cases */
+  g_assert_null (g_memdup2 (NULL, 1024));
+  g_assert_null (g_memdup2 (str, 0));
+  g_assert_null (g_memdup2 (NULL, 0));
+
+  /* Testing normal usage cases */
+  str_dup = g_memdup2 (str, strlen (str) + 1);
+  g_assert_nonnull (str_dup);
+  g_assert_cmpstr (str, ==, str_dup);
+
+  g_free (str_dup);
+}
+
 /* Testing g_strpcpy() function with various positive and negative cases */
 static void
 test_stpcpy (void)
@@ -2523,6 +2545,7 @@ main (int   argc,
   g_test_add_func ("/strfuncs/has-prefix", test_has_prefix);
   g_test_add_func ("/strfuncs/has-suffix", test_has_suffix);
   g_test_add_func ("/strfuncs/memdup", test_memdup);
+  g_test_add_func ("/strfuncs/memdup2", test_memdup2);
   g_test_add_func ("/strfuncs/stpcpy", test_stpcpy);
   g_test_add_func ("/strfuncs/str_match_string", test_str_match_string);
   g_test_add_func ("/strfuncs/str_tokenize_and_fold", test_str_tokenize_and_fold);
--
2.30.1


code:
Backport of:

From be8834340a2d928ece82025463ae23dee2c333d0 Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Thu, 4 Feb 2021 13:37:56 +0000
Subject: [PATCH 02/11] gio: Use g_memdup2() instead of g_memdup() in obvious
 places
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Convert all the call sites which use `g_memdup()`’s length argument
trivially (for example, by passing a `sizeof()`), so that they use
`g_memdup2()` instead.

In almost all of these cases the use of `g_memdup()` would not have
caused problems, but it will soon be deprecated, so best port away from
it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #2319
---
 gio/gdbusconnection.c                 | 5 +++--
 gio/gdbusinterfaceskeleton.c          | 3 ++-
 gio/gfile.c                           | 7 ++++---
 gio/gsettingsschema.c                 | 5 +++--
 gio/gwin32registrykey.c               | 8 +++++---
 gio/tests/async-close-output-stream.c | 6 ++++--
 gio/tests/gdbus-export.c              | 5 +++--
 gio/win32/gwinhttpfile.c              | 9 +++++----
 8 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index f1f0921d4..d56453486 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -110,6 +110,7 @@
 #include "gasyncinitable.h"
 #include "giostream.h"
 #include "gasyncresult.h"
+#include "gstrfuncsprivate.h"
 #include "gtask.h"
 #include "gmarshal-internal.h"

@@ -3997,7 +3998,7 @@ _g_dbus_interface_vtable_copy (const GDBusInterfaceVTable *vtable)
   /* Don't waste memory by copying padding - remember to update this
    * when changing struct _GDBusInterfaceVTable in gdbusconnection.h
    */
-  return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
+  return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
 }

 static void
@@ -4014,7 +4015,7 @@ _g_dbus_subtree_vtable_copy (const GDBusSubtreeVTable *vtable)
   /* Don't waste memory by copying padding - remember to update this
    * when changing struct _GDBusSubtreeVTable in gdbusconnection.h
    */
-  return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
+  return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
 }

 static void
diff --git a/gio/gdbusinterfaceskeleton.c b/gio/gdbusinterfaceskeleton.c
index 4a06516c1..4a4b719a5 100644
--- a/gio/gdbusinterfaceskeleton.c
+++ b/gio/gdbusinterfaceskeleton.c
@@ -28,6 +28,7 @@
 #include "gdbusmethodinvocation.h"
 #include "gdbusconnection.h"
 #include "gmarshal-internal.h"
+#include "gstrfuncsprivate.h"
 #include "gtask.h"
 #include "gioerror.h"

@@ -701,7 +702,7 @@ add_connection_locked (GDBusInterfaceSkeleton *interface_,
        * properly before building the hooked_vtable, so we create it
        * once at the last minute.
        */
-      interface_->priv->hooked_vtable = g_memdup (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
+      interface_->priv->hooked_vtable = g_memdup2 (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
       interface_->priv->hooked_vtable->method_call = skeleton_intercept_handle_method_call;
     }

diff --git a/gio/gfile.c b/gio/gfile.c
index ba93f7c75..88b341e7d 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -60,6 +60,7 @@
 #include "gasyncresult.h"
 #include "gioerror.h"
 #include "glibintl.h"
+#include "gstrfuncsprivate.h"

 /**
@@ -7884,7 +7885,7 @@ measure_disk_usage_progress (gboolean reporting,
   g_main_context_invoke_full (g_task_get_context (task),
                               g_task_get_priority (task),
                               measure_disk_usage_invoke_progress,
-                              g_memdup (&progress, sizeof progress),
+                              g_memdup2 (&progress, sizeof progress),
                               g_free);
 }

@@ -7902,7 +7903,7 @@ measure_disk_usage_thread (GTask        *task,
                                  data->progress_callback ? measure_disk_usage_progress : NULL, task,
                                  &result.disk_usage, &result.num_dirs, &result.num_files,
                                  &error))
-    g_task_return_pointer (task, g_memdup (&result, sizeof result), g_free);
+    g_task_return_pointer (task, g_memdup2 (&result, sizeof result), g_free);
   else
     g_task_return_error (task, error);
 }
@@ -7926,7 +7927,7 @@ g_file_real_measure_disk_usage_async (GFile                        *file,

   task = g_task_new (file, cancellable, callback, user_data);
   g_task_set_source_tag (task, g_file_real_measure_disk_usage_async);
-  g_task_set_task_data (task, g_memdup (&data, sizeof data), g_free);
+  g_task_set_task_data (task, g_memdup2 (&data, sizeof data), g_free);
   g_task_set_priority (task, io_priority);

   g_task_run_in_thread (task, measure_disk_usage_thread);
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index 3a60b8c64..dded9b1ca 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -20,6 +20,7 @@

 #include "gsettingsschema-internal.h"
 #include "gsettings.h"
+#include "gstrfuncsprivate.h"

 #include "gvdb/gvdb-reader.h"
 #include "strinfo.c"
@@ -1058,9 +1059,9 @@ g_settings_schema_list_children (GSettingsSchema *schema)

       if (g_str_has_suffix (key, "/"))
         {
-          gint length = strlen (key);
+          gsize length = strlen (key);

-          strv[j] = g_memdup (key, length);
+          strv[j] = g_memdup2 (key, length);
           strv[j][length - 1] = '\0';
           j++;
         }
diff --git a/gio/gwin32registrykey.c b/gio/gwin32registrykey.c
index c19fede4e..619fd48af 100644
--- a/gio/gwin32registrykey.c
+++ b/gio/gwin32registrykey.c
@@ -28,6 +28,8 @@
 #include <ntstatus.h>
 #include <winternl.h>

+#include "gstrfuncsprivate.h"
+
 #ifndef _WDMDDK_
 typedef enum _KEY_INFORMATION_CLASS {
   KeyBasicInformation,
@@ -247,7 +249,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
   new_iter->value_name_size = iter->value_name_size;

   if (iter->value_data != NULL)
-    new_iter->value_data = g_memdup (iter->value_data, iter->value_data_size);
+    new_iter->value_data = g_memdup2 (iter->value_data, iter->value_data_size);

   new_iter->value_data_size = iter->value_data_size;

@@ -268,8 +270,8 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
   new_iter->value_data_expanded_charsize = iter->value_data_expanded_charsize;

   if (iter->value_data_expanded_u8 != NULL)
-    new_iter->value_data_expanded_u8 = g_memdup (iter->value_data_expanded_u8,
-                                                 iter->value_data_expanded_charsize);
+    new_iter->value_data_expanded_u8 = g_memdup2 (iter->value_data_expanded_u8,
+                                                  iter->value_data_expanded_charsize);

   new_iter->value_data_expanded_u8_size = iter->value_data_expanded_charsize;

diff --git a/gio/tests/async-close-output-stream.c b/gio/tests/async-close-output-stream.c
index 5f6620275..d3f97a119 100644
--- a/gio/tests/async-close-output-stream.c
+++ b/gio/tests/async-close-output-stream.c
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <string.h>

+#include "gstrfuncsprivate.h"
+
 #define DATA_TO_WRITE "Hello world\n"

 typedef struct
@@ -147,9 +149,9 @@ prepare_data (SetupData *data,

   data->expected_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->data_stream));

-  g_assert_cmpint (data->expected_size, >, 0);
+  g_assert_cmpuint (data->expected_size, >, 0);

-  data->expected_output = g_memdup (written, (guint)data->expected_size);
+  data->expected_output = g_memdup2 (written, data->expected_size);

   /* then recreate the streams and prepare them for the asynchronous close */
   destroy_streams (data);
diff --git a/gio/tests/gdbus-export.c b/gio/tests/gdbus-export.c
index 506c7458a..5513306f8 100644
--- a/gio/tests/gdbus-export.c
+++ b/gio/tests/gdbus-export.c
@@ -23,6 +23,7 @@
 #include <string.h>

 #include "gdbus-tests.h"
+#include "gstrfuncsprivate.h"

 /* all tests rely on a shared mainloop */
 static GMainLoop *loop = NULL;
@@ -671,7 +672,7 @@ subtree_introspect (GDBusConnection       *connection,
       g_assert_not_reached ();
     }

-  return g_memdup (interfaces, 2 * sizeof (void *));
+  return g_memdup2 (interfaces, 2 * sizeof (void *));
 }

 static const GDBusInterfaceVTable *
@@ -727,7 +728,7 @@ dynamic_subtree_introspect (GDBusConnection       *connection,
 {
   const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL };

-  return g_memdup (interfaces, 2 * sizeof (void *));
+  return g_memdup2 (interfaces, 2 * sizeof (void *));
 }

 static const GDBusInterfaceVTable *
diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c
index cf5eed31d..040ee8564 100644
--- a/gio/win32/gwinhttpfile.c
+++ b/gio/win32/gwinhttpfile.c
@@ -29,6 +29,7 @@
 #include "gio/gfile.h"
 #include "gio/gfileattribute.h"
 #include "gio/gfileinfo.h"
+#include "gstrfuncsprivate.h"
 #include "gwinhttpfile.h"
 #include "gwinhttpfileinputstream.h"
 #include "gwinhttpfileoutputstream.h"
@@ -393,10 +394,10 @@ g_winhttp_file_resolve_relative_path (GFile      *file,
   child = g_object_new (G_TYPE_WINHTTP_FILE, NULL);
   child->vfs = winhttp_file->vfs;
   child->url = winhttp_file->url;
-  child->url.lpszScheme = g_memdup (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
-  child->url.lpszHostName = g_memdup (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
-  child->url.lpszUserName = g_memdup (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
-  child->url.lpszPassword = g_memdup (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
+  child->url.lpszScheme = g_memdup2 (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
+  child->url.lpszHostName = g_memdup2 (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
+  child->url.lpszUserName = g_memdup2 (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
+  child->url.lpszPassword = g_memdup2 (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
   child->url.lpszUrlPath = wnew_path;
   child->url.dwUrlPathLength = wcslen (wnew_path);
   child->url.lpszExtraInfo = NULL;
--
2.30.1


code:
From 6110caea45b235420b98cd41d845cc92238f6781 Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Thu, 4 Feb 2021 13:39:25 +0000
Subject: [PATCH 03/11] gobject: Use g_memdup2() instead of g_memdup() in
 obvious places
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Convert all the call sites which use `g_memdup()`’s length argument
trivially (for example, by passing a `sizeof()`), so that they use
`g_memdup2()` instead.

In almost all of these cases the use of `g_memdup()` would not have
caused problems, but it will soon be deprecated, so best port away from
it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #2319
---
 gobject/gsignal.c     | 3 ++-
 gobject/gtype.c       | 9 +++++----
 gobject/gtypemodule.c | 3 ++-
 gobject/tests/param.c | 4 +++-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/gobject/gsignal.c b/gobject/gsignal.c
index 77d8f211e..41c54ab57 100644
--- a/gobject/gsignal.c
+++ b/gobject/gsignal.c
@@ -28,6 +28,7 @@
 #include <signal.h>

 #include "gsignal.h"
+#include "gstrfuncsprivate.h"
 #include "gtype-private.h"
 #include "gbsearcharray.h"
 #include "gvaluecollector.h"
@@ -1730,7 +1731,7 @@ g_signal_newv (const gchar       *signal_name,
   node->single_va_closure_is_valid = FALSE;
   node->flags = signal_flags & G_SIGNAL_FLAGS_MASK;
   node->n_params = n_params;
-  node->param_types = g_memdup (param_types, sizeof (GType) * n_params);
+  node->param_types = g_memdup2 (param_types, sizeof (GType) * n_params);
   node->return_type = return_type;
   node->class_closure_bsa = NULL;
   if (accumulator)
diff --git a/gobject/gtype.c b/gobject/gtype.c
index 7d3789400..8441b90e9 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -33,6 +33,7 @@

 #include "glib-private.h"
 #include "gconstructor.h"
+#include "gstrfuncsprivate.h"

 #ifdef G_OS_WIN32
 #include <windows.h>
@@ -1470,7 +1471,7 @@ type_add_interface_Wm (TypeNode             *node,
   iholder->next = iface_node_get_holders_L (iface);
   iface_node_set_holders_W (iface, iholder);
   iholder->instance_type = NODE_TYPE (node);
-  iholder->info = info ? g_memdup (info, sizeof (*info)) : NULL;
+  iholder->info = info ? g_memdup2 (info, sizeof (*info)) : NULL;
   iholder->plugin = plugin;

   /* create an iface entry for this type */
@@ -1731,7 +1732,7 @@ type_iface_retrieve_holder_info_Wm (TypeNode *iface,
         INVALID_RECURSION ("g_type_plugin_*", iholder->plugin, NODE_NAME (iface));

       check_interface_info_I (iface, instance_type, &tmp_info);
-      iholder->info = g_memdup (&tmp_info, sizeof (tmp_info));
+      iholder->info = g_memdup2 (&tmp_info, sizeof (tmp_info));
     }

   return iholder;	/* we don't modify write lock upon returning NULL */
@@ -2016,10 +2017,10 @@ type_iface_vtable_base_init_Wm (TypeNode *iface,
       IFaceEntry *pentry = type_lookup_iface_entry_L (pnode, iface);

       if (pentry)
-	vtable = g_memdup (pentry->vtable, iface->data->iface.vtable_size);
+	vtable = g_memdup2 (pentry->vtable, iface->data->iface.vtable_size);
     }
   if (!vtable)
-    vtable = g_memdup (iface->data->iface.dflt_vtable, iface->data->iface.vtable_size);
+    vtable = g_memdup2 (iface->data->iface.dflt_vtable, iface->data->iface.vtable_size);
   entry->vtable = vtable;
   vtable->g_type = NODE_TYPE (iface);
   vtable->g_instance_type = NODE_TYPE (node);
diff --git a/gobject/gtypemodule.c b/gobject/gtypemodule.c
index 4ecaf8c88..20911fafd 100644
--- a/gobject/gtypemodule.c
+++ b/gobject/gtypemodule.c
@@ -19,6 +19,7 @@

 #include <stdlib.h>

+#include "gstrfuncsprivate.h"
 #include "gtypeplugin.h"
 #include "gtypemodule.h"

@@ -436,7 +437,7 @@ g_type_module_register_type (GTypeModule     *module,
   module_type_info->loaded = TRUE;
   module_type_info->info = *type_info;
   if (type_info->value_table)
-    module_type_info->info.value_table = g_memdup (type_info->value_table,
+    module_type_info->info.value_table = g_memdup2 (type_info->value_table,
 						   sizeof (GTypeValueTable));

   return module_type_info->type;
diff --git a/gobject/tests/param.c b/gobject/tests/param.c
index 758289bf8..971cff162 100644
--- a/gobject/tests/param.c
+++ b/gobject/tests/param.c
@@ -2,6 +2,8 @@
 #include <glib-object.h>
 #include <stdlib.h>

+#include "gstrfuncsprivate.h"
+
 static void
 test_param_value (void)
 {
@@ -851,7 +853,7 @@ main (int argc, char *argv[])
             test_path = g_strdup_printf ("/param/implement/subprocess/%d-%d-%d-%d",
                                          data.change_this_flag, data.change_this_type,
                                          data.use_this_flag, data.use_this_type);
-            test_data = g_memdup (&data, sizeof (TestParamImplementData));
+            test_data = g_memdup2 (&data, sizeof (TestParamImplementData));
             g_test_add_data_func_full (test_path, test_data, test_param_implement_child, g_free);
             g_free (test_path);
           }
--
2.30.1