Submitted By:            Randy McMurchy <linux@mcmurchy.com>
Date:                    2025-07-25
Initial Package Version: 4.15.2
Upstream Status:         Not submitted
Origin:                  Existing commands in BLFS book and
                         https://lists.gnu.org/archive/html/bug-gnu-utils/2025-03/msg00000.html
Description:             Fixes numerous GCC compilation errors and security issues



diff -Nuar sharutils-4.15.2.orig/lib/fflush.c sharutils-4.15.2/lib/fflush.c
--- sharutils-4.15.2.orig/lib/fflush.c	2015-05-30 10:34:54.000000000 -0500
+++ sharutils-4.15.2/lib/fflush.c	2025-07-25 01:14:13.779768249 -0500
@@ -33,7 +33,7 @@
 #undef fflush
 
 
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
 
 /* Clear the stream's ungetc buffer, preserving the value of ftello (fp).  */
 static void
@@ -72,7 +72,7 @@
 
 #endif
 
-#if ! (defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
+#if ! (defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
 
 # if (defined __sferror || defined __DragonFly__ || defined __ANDROID__) && defined __SNPT
 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Android */
@@ -148,7 +148,7 @@
   if (stream == NULL || ! freading (stream))
     return fflush (stream);
 
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
 
   clear_ungetc_buffer_preserving_position (stream);
 
diff -Nuar sharutils-4.15.2.orig/lib/fpurge.c sharutils-4.15.2/lib/fpurge.c
--- sharutils-4.15.2.orig/lib/fpurge.c	2015-05-30 10:34:54.000000000 -0500
+++ sharutils-4.15.2/lib/fpurge.c	2025-07-25 01:14:13.779970527 -0500
@@ -62,7 +62,7 @@
   /* Most systems provide FILE as a struct and the necessary bitmask in
      <stdio.h>, because they need it for implementing getc() and putc() as
      fast macros.  */
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   fp->_IO_read_end = fp->_IO_read_ptr;
   fp->_IO_write_ptr = fp->_IO_write_base;
   /* Avoid memory leak when there is an active ungetc buffer.  */
diff -Nuar sharutils-4.15.2.orig/lib/freading.c sharutils-4.15.2/lib/freading.c
--- sharutils-4.15.2.orig/lib/freading.c	2015-05-30 10:34:54.000000000 -0500
+++ sharutils-4.15.2/lib/freading.c	2025-07-25 01:14:13.780083716 -0500
@@ -31,7 +31,7 @@
   /* Most systems provide FILE as a struct and the necessary bitmask in
      <stdio.h>, because they need it for implementing getc() and putc() as
      fast macros.  */
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   return ((fp->_flags & _IO_NO_WRITES) != 0
           || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0
               && fp->_IO_read_base != NULL));
diff -Nuar sharutils-4.15.2.orig/lib/fseeko.c sharutils-4.15.2/lib/fseeko.c
--- sharutils-4.15.2.orig/lib/fseeko.c	2015-05-30 10:34:54.000000000 -0500
+++ sharutils-4.15.2/lib/fseeko.c	2025-07-25 01:14:13.780341591 -0500
@@ -47,7 +47,7 @@
 #endif
 
   /* These tests are based on fpurge.c.  */
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   if (fp->_IO_read_end == fp->_IO_read_ptr
       && fp->_IO_write_ptr == fp->_IO_write_base
       && fp->_IO_save_base == NULL)
@@ -123,7 +123,7 @@
           return -1;
         }
 
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
       fp->_flags &= ~_IO_EOF_SEEN;
       fp->_offset = pos;
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
diff -Nuar sharutils-4.15.2.orig/lib/stdio-impl.h sharutils-4.15.2/lib/stdio-impl.h
--- sharutils-4.15.2.orig/lib/stdio-impl.h	2015-05-30 10:34:57.000000000 -0500
+++ sharutils-4.15.2/lib/stdio-impl.h	2025-07-25 01:14:13.789322087 -0500
@@ -111,3 +111,4 @@
 # endif
 
 #endif
+#define _IO_IN_BACKUP 0x100
diff -Nuar sharutils-4.15.2.orig/lib/system.h sharutils-4.15.2/lib/system.h
--- sharutils-4.15.2.orig/lib/system.h	2015-05-22 10:21:37.000000000 -0500
+++ sharutils-4.15.2/lib/system.h	2025-07-25 01:15:16.853678107 -0500
@@ -52,7 +52,7 @@
 #endif
 
 #if !HAVE_DECL_STRTOIMAX && !defined strtoimax
-intmax_t strtoimax ();
+intmax_t strtoimax (const char *nptr, char **endptr, int base);
 #endif
 
 #if HAVE_STRING_H
@@ -75,8 +75,8 @@
 # include <unistd.h>
 #endif
 
-FILE *fdopen ();
-FILE *popen ();
+FILE *fdopen (int fd, const char *mode);
+FILE *popen (const char *command, const char *type);
 
 /* Global functions of the shar package.  */
 
diff -Nuar sharutils-4.15.2.orig/m4/getcwd.m4 sharutils-4.15.2/m4/getcwd.m4
--- sharutils-4.15.2.orig/m4/getcwd.m4	2015-05-30 10:34:59.000000000 -0500
+++ sharutils-4.15.2/m4/getcwd.m4	2025-07-25 01:15:03.131993453 -0500
@@ -21,7 +21,7 @@
 #         include <direct.h>
 #        endif
 #        ifndef getcwd
-         char *getcwd ();
+         char *getcwd (char *buf, size_t size);
 #        endif
 ]], [[
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
diff -Nuar sharutils-4.15.2.orig/m4/stdbool.m4 sharutils-4.15.2/m4/stdbool.m4
--- sharutils-4.15.2.orig/m4/stdbool.m4	2015-05-30 10:34:59.000000000 -0500
+++ sharutils-4.15.2/m4/stdbool.m4	2025-07-25 01:14:55.553814707 -0500
@@ -1,27 +1,40 @@
 # Check for stdbool.h that conforms to C99.
 
-dnl Copyright (C) 2002-2006, 2009-2015 Free Software Foundation, Inc.
+dnl Copyright (C) 2002-2006, 2009-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
-#serial 5
+#serial 10
 
 # Prepare for substituting <stdbool.h> if it is not supported.
 
 AC_DEFUN([AM_STDBOOL_H],
 [
   AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
-  # Define two additional variables used in the Makefile substitution.
-
+  dnl On some platforms, <stdbool.h> does not exist or does not conform to C99.
+  dnl On Solaris 10 with CC=cc CXX=CC, <stdbool.h> exists but is not usable
+  dnl in C++ mode (and no <cstdbool> exists). In this case, we use our
+  dnl replacement, also in C mode (for binary compatibility between C and C++).
   if test "$ac_cv_header_stdbool_h" = yes; then
-    STDBOOL_H=''
+    case "$host_os" in
+      solaris*)
+        if test -z "$GCC"; then
+          GL_GENERATE_STDBOOL_H=true
+        else
+          GL_GENERATE_STDBOOL_H=false
+        fi
+        ;;
+      *)
+        GL_GENERATE_STDBOOL_H=false
+        ;;
+    esac
   else
-    STDBOOL_H='stdbool.h'
+    GL_GENERATE_STDBOOL_H=true
   fi
-  AC_SUBST([STDBOOL_H])
-  AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
+  AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test "$GL_GENERATE_STDBOOL_H" = "true"])
 
   if test "$ac_cv_type__Bool" = yes; then
     HAVE__BOOL=1
@@ -31,70 +44,76 @@
   AC_SUBST([HAVE__BOOL])
 ])
 
-# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
-AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
-
-# This version of the macro is needed in autoconf <= 2.68.
+m4_version_prereq([2.72], [], [
 
 AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
-  [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
+  [AC_CHECK_TYPES([_Bool])
+   AC_CACHE_CHECK([for stdbool.h that conforms to C99 or later],
      [ac_cv_header_stdbool_h],
      [AC_COMPILE_IFELSE(
         [AC_LANG_PROGRAM(
-           [[
-             #include <stdbool.h>
-             #ifndef bool
-              "error: bool is not defined"
+           [[#include <stdbool.h>
+
+             /* "true" and "false" should be usable in #if expressions and
+                integer constant expressions, and "bool" should be a valid
+                type name.
+
+                Although C99 requires bool, true, and false to be macros,
+                C23 and C++11 overrule that, so do not test for that.
+                Although C99 requires __bool_true_false_are_defined and
+                _Bool, C23 says they are obsolescent, so do not require
+                them.  */
+
+             #if !true
+               #error "'true' is not true"
              #endif
-             #ifndef false
-              "error: false is not defined"
+             #if true != 1
+               #error "'true' is not equal to 1"
              #endif
+             char b[true == 1 ? 1 : -1];
+             char c[true];
+
              #if false
-              "error: false is not 0"
+               #error "'false' is not false"
              #endif
-             #ifndef true
-              "error: true is not defined"
-             #endif
-             #if true != 1
-              "error: true is not 1"
-             #endif
-             #ifndef __bool_true_false_are_defined
-              "error: __bool_true_false_are_defined is not defined"
+             #if false != 0
+               #error "'false' is not equal to 0"
              #endif
+             char d[false == 0 ? 1 : -1];
+
+             enum { e = false, f = true, g = false * true, h = true * 256 };
 
-             struct s { _Bool s: 1; _Bool t; } s;
+             char i[(bool) 0.5 == true ? 1 : -1];
+             char j[(bool) 0.0 == false ? 1 : -1];
+             char k[sizeof (bool) > 0 ? 1 : -1];
+
+             struct sb { bool s: 1; bool t; } s;
+             char l[sizeof s.t > 0 ? 1 : -1];
 
-             char a[true == 1 ? 1 : -1];
-             char b[false == 0 ? 1 : -1];
-             char c[__bool_true_false_are_defined == 1 ? 1 : -1];
-             char d[(bool) 0.5 == true ? 1 : -1];
-             /* See body of main program for 'e'.  */
-             char f[(_Bool) 0.0 == false ? 1 : -1];
-             char g[true];
-             char h[sizeof (_Bool)];
-             char i[sizeof s.t];
-             enum { j = false, k = true, l = false * true, m = true * 256 };
              /* The following fails for
                 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
-             _Bool n[m];
-             char o[sizeof n == m * sizeof n[0] ? 1 : -1];
-             char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
+             bool m[h];
+             char n[sizeof m == h * sizeof m[0] ? 1 : -1];
+             char o[-1 - (bool) 0 < 0 ? 1 : -1];
              /* Catch a bug in an HP-UX C compiler.  See
-                http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
-                http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
+                https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
+                https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
               */
-             _Bool q = true;
-             _Bool *pq = &q;
+             bool p = true;
+             bool *pp = &p;
            ]],
            [[
-             bool e = &s;
-             *pq |= q;
-             *pq |= ! q;
-             /* Refer to every declared value, to avoid compiler optimizations.  */
-             return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
-                     + !m + !n + !o + !p + !q + !pq);
+             bool ps = &s;
+             *pp |= p;
+             *pp |= ! p;
+
+             /* Refer to every declared value, so they cannot be
+                discarded as unused.  */
+             return (!b + !c + !d + !e + !f + !g + !h + !i + !j + !k
+                     + !l + !m + !n + !o + !p + !pp + !ps);
            ]])],
         [ac_cv_header_stdbool_h=yes],
         [ac_cv_header_stdbool_h=no])])
-   AC_CHECK_TYPES([_Bool])
-])
+])# AC_CHECK_HEADER_STDBOOL
+
+]) # m4_version_prereq 2.72
diff -Nuar sharutils-4.15.2.orig/src/encode.c sharutils-4.15.2/src/encode.c
--- sharutils-4.15.2.orig/src/encode.c	2014-02-02 13:25:31.000000000 -0600
+++ sharutils-4.15.2/src/encode.c	2025-07-25 01:15:16.853948593 -0500
@@ -30,9 +30,7 @@
 `------------------------------------------*/
 
 static void
-write_encoded_bytes (group, file)
-     char *group;
-     FILE *file;
+write_encoded_bytes (char *group, FILE *file)
 {
   int c1, c2, c3, c4;
 
@@ -52,10 +50,7 @@
 `--------------------------------------------------------------------*/
 
 static int
-read_raw_bytes (file, buffer, buffer_size)
-     FILE *file;
-     char *buffer;
-     int buffer_size;
+read_raw_bytes (FILE *file, char *buffer, int buffer_size)
 {
   int character;
   int counter;
@@ -75,9 +70,7 @@
 `----------------------------------------------------*/
 
 void
-copy_file_encoded (input, output)
-     FILE *input;
-     FILE *output;
+copy_file_encoded (FILE *input, FILE *output)
 {
   char buffer[LINE_BUFFER_SIZE];
   int counter;
diff -Nuar sharutils-4.15.2.orig/src/shar-opts.h sharutils-4.15.2/src/shar-opts.h
--- sharutils-4.15.2.orig/src/shar-opts.h	2015-05-30 10:34:12.000000000 -0500
+++ sharutils-4.15.2/src/shar-opts.h	2025-07-25 01:12:45.403623754 -0500
@@ -352,7 +352,7 @@
  *  global exported definitions
  */
 #include "local.h"
-char const * const program_name;
+extern char const * const program_name;
 
 extern bool initialization_done;
 extern int optidx;
diff -Nuar sharutils-4.15.2.orig/src/shar.c sharutils-4.15.2/src/shar.c
--- sharutils-4.15.2.orig/src/shar.c	2015-05-22 10:27:34.000000000 -0500
+++ sharutils-4.15.2/src/shar.c	2025-07-25 01:15:16.854461883 -0500
@@ -110,7 +110,7 @@
 #define IS_GRAPH(_c) (isprint (to_uchar (_c)) && !isspace (to_uchar (_c)))
 #endif
 
-struct tm *localtime ();
+struct tm *localtime (const time_t *timep);
 
 #if MSDOS
           /* 1 extra for CR.  */
diff -Nuar sharutils-4.15.2.orig/src/unshar-opts.h sharutils-4.15.2/src/unshar-opts.h
--- sharutils-4.15.2.orig/src/unshar-opts.h	2015-05-30 10:34:18.000000000 -0500
+++ sharutils-4.15.2/src/unshar-opts.h	2025-07-25 01:12:45.404284617 -0500
@@ -192,7 +192,7 @@
 extern size_t       separator_str_len;
 
 #include "local.h"
-char const * const program_name;
+extern char const * const program_name;
 
 
 /* * * * * *
diff -Nuar sharutils-4.15.2.orig/src/unshar.c sharutils-4.15.2/src/unshar.c
--- sharutils-4.15.2.orig/src/unshar.c	2015-01-06 20:14:10.000000000 -0600
+++ sharutils-4.15.2/src/unshar.c	2025-07-25 01:12:45.400362293 -0500
@@ -240,7 +240,7 @@
       off_t position = ftello (file);
 
       /* Read next line, fail if no more and no previous process.  */
-      if (!fgets (rw_buffer, BUFSIZ, file))
+      if (!fgets (rw_buffer, rw_base_size, file))
 	{
 	  if (!start)
 	    error (0, 0, _("Found no shell commands in %s"), name);
diff -Nuar sharutils-4.15.2.orig/src/uudecode-opts.h sharutils-4.15.2/src/uudecode-opts.h
--- sharutils-4.15.2.orig/src/uudecode-opts.h	2015-05-30 10:34:21.000000000 -0500
+++ sharutils-4.15.2/src/uudecode-opts.h	2025-07-25 01:12:45.404690307 -0500
@@ -170,7 +170,7 @@
  *  global exported definitions
  */
 #include "local.h"
-char const * const program_name;
+extern char const * const program_name;
 
 
 /* * * * * *
diff -Nuar sharutils-4.15.2.orig/src/uudecode.c sharutils-4.15.2/src/uudecode.c
--- sharutils-4.15.2.orig/src/uudecode.c	2015-05-22 10:17:10.000000000 -0500
+++ sharutils-4.15.2/src/uudecode.c	2025-07-25 01:15:16.854913875 -0500
@@ -82,7 +82,7 @@
 #define UU_CHMOD(_n, _fd, _m)   chmod ((_n), UU_MODE_BITS(_m))
 #endif
 
-struct passwd *getpwnam ();
+struct passwd *getpwnam (const char *name);
 
 static uudecode_exit_code_t read_stduu(
         const char *inname, const char *outname);
diff -Nuar sharutils-4.15.2.orig/src/uuencode-opts.h sharutils-4.15.2/src/uuencode-opts.h
--- sharutils-4.15.2.orig/src/uuencode-opts.h	2015-05-30 10:34:25.000000000 -0500
+++ sharutils-4.15.2/src/uuencode-opts.h	2025-07-25 01:12:45.404816743 -0500
@@ -166,7 +166,7 @@
  *  global exported definitions
  */
 #include "local.h"
-char const * const program_name;
+extern char const * const program_name;
 
 
 /* * * * * *
