public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
* [PATCH rebase] peflags: Fix ULONG range checks
@ 2023-08-07 14:07 Christian Franke
  2023-08-07 18:50 ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Franke @ 2023-08-07 14:07 UTC (permalink / raw)
  To: cygwin-apps

[-- Attachment #1: Type: text/plain, Size: 101 bytes --]

Minor issue found during tests of the upcoming 'peflags --timestamp' patch.

-- 
Regards,
Christian


[-- Attachment #2: 0001-peflags-Fix-ULONG-range-checks.patch --]
[-- Type: text/plain, Size: 1542 bytes --]

From 9da405da78e92dc8263239e25365bee3167f185e Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Mon, 7 Aug 2023 13:42:50 +0200
Subject: [PATCH] peflags: Fix ULONG range checks

Don't use ULONG_MAX from <limits.h> because ULONG is not necessarily
'unsigned long'.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 peflags.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/peflags.c b/peflags.c
index 93eaa0b..d98b121 100644
--- a/peflags.c
+++ b/peflags.c
@@ -30,7 +30,6 @@
 #include <unistd.h>
 #include <getopt.h>
 #include <errno.h>
-#include <limits.h>
 #if defined (__CYGWIN__) || defined (__MSYS__)
 #include <sys/mman.h>
 #endif
@@ -598,7 +597,7 @@ handle_num_option (const char *option_name,
 	   || sizeof_vals[option_index].value > 0x0000ffffffffffffULL
 	   /* Just a ULONG value */
 	   || (sizeof_vals[option_index].is_ulong
-	       && sizeof_vals[option_index].value > ULONG_MAX))
+	       && sizeof_vals[option_index].value > 0x00000000ffffffffULL))
     {
       fprintf (stderr, "Invalid argument for %s: %s\n", 
 	       option_name, option_arg);
@@ -960,7 +959,7 @@ get_and_set_size (const pe_file *pep, sizeof_values_t *val)
     }
   else if (val->handle == DO_WRITE)
     {
-      if ((!pep->is_64bit || val->is_ulong) && val->value >= ULONG_MAX)
+      if ((!pep->is_64bit || val->is_ulong) && val->value > 0x00000000ffffffffULL)
 	{
 	  fprintf (stderr, "%s: Skip writing %s, value too big\n",
 		   pep->pathname, val->name);
-- 
2.39.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-08  8:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-07 14:07 [PATCH rebase] peflags: Fix ULONG range checks Christian Franke
2023-08-07 18:50 ` Corinna Vinschen
2023-08-08  8:06   ` Christian Franke
2023-08-08  8:37     ` Corinna Vinschen
2023-08-08  8:40       ` Christian Franke
2023-08-08  8:55         ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).