Re: cygport cygautoreconf failure with AC_CONFIG_MACRO_DIRS

2023-08-08 Thread Brian Inglis via Cygwin-apps

On 2023-08-08 12:14, Jon Turney via Cygwin-apps wrote:

On 03/08/2023 17:21, Brian Inglis via Cygwin-apps wrote:

Hi folks,

Trying to build updated jq package, get cygautoreconf directory creation and 
existence bugs.

[...]


Cygport dies processing AC_CONFIG_SUBDIRS([modules/oniguruma]) under two 
levels of AS_IF (which handle existence of oniguruma library module or 
libonig-devel at default or custom locations with or without configure scripts 
in configure.ac) with:


Could not find modules/oniguruma/configure.ac or modules/oniguruma/configure.in


I'm not able to reproduce this problem.

Can you provide the jq.cygport you are using.

Also, can you be clear as to whether you have libonig-devel installed or not?


Hi Jon,

Attached jq.cygport.

As the cygport debug prep make log shows, libonig-devel is in 
DEPEND/BUILD_REQUIRES and installed.


Installed cygport is latest available 0.36.6-1.

With the attached cygautoreconf patch applied, it builds.

--
Take care. Thanks, Brian Inglis  Calgary, Alberta, Canada

La perfection est atteinte   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer but when there is no more to cut
-- Antoine de Saint-Exupéry
NAME=jq
VERSION=1.6
RELEASE=1
VERSION=1.7
RELEASE=0.rc1

CATEGORY="Text"
SUMMARY="Lightweight and flexible JSON processor"
DESCRIPTION="jq is like sed for JSON data - you can use it to slice and
filter and map and transform structured data with the same ease
that sed, awk, grep and friends let you play with text."

HOMEPAGE=https://stedolan.github.io/$NAME/
SRC_URI=https://github.com/stedolan/$NAME/releases/download/$NAME-$VERSION/$NAME-$VERSION.tar.gz
HOMEPAGE=https://jqlang.github.io/$NAME/
SRC_URI=https://github.com/jqlang/$NAME/archive/refs/tags/$NAME-$VERSION${RELEASE#*.}.tar.gz
SRC_DIR=$NAME-$NAME-$VERSION${RELEASE#*.}
PATCH_URI=1.4-no-undefined.patch

DEPEND="libonig-devel"
DEPEND=" autoconf automake bison flex gcc-core"
DEPEND+=" libtool pkg-config python3 rubygems"  # should have pipenv if packaged
BUILD_REQUIRES="$DEPEND"

LDFLAGS="$LDFLAGS -Wl,--no-allow-shlib-undefined -Wl,--no-undefined"

CYGCONF_ARGS="
lt_no_undefined_flag=-no-undefined
no_undefined_flag=-no-undefined
"
#--enable-all-staticlink jq with static libraries only
#--enable-asan  enable address sanitizer
#--enable-dependency-tracking   do not reject slow dependency extractors
#   --disable-dependency-tracking   speeds up one-time build
#   --disable-docs  don't build docs
#--enable-error-injection   build and test with error injection
#--enable-fast-install[=PKGS]   optimize for fast installation 
[default=yes]
#--enable-gcov  enable gcov code coverage tool
#   --disable-libtool-lock  avoid locking (might break parallel 
builds)
#   --disable-maintainer-mode   disable make rules and dependencies not 
useful (and sometimes confusing) to the casual installer
#   --disable-option-checking   ignore unrecognized --enable/--with 
options
#--enable-pthread-tls   Enable use of pthread thread local 
storage
#--enable-shared[=PKGS] build shared libraries [default=yes]
#--enable-silent-rules  less verbose build output (undo: "make 
V=1")
#   --disable-silent-rules  verbose build output (undo: "make V=0")
#--enable-static[=PKGS] build static libraries [default=yes]
#--enable-ubsan enable undefined behavior sanitizer
#   --disable-valgrind  do not run tests under Valgrind
#  --with-aix-soname=aix|svr4|both  shared library versioning (aka 
"SONAME") variant to provide on AIX, [default=aix].
#  --with-gnu-ldassume the C compiler uses GNU ld 
[default=no]
#  --with-oniguruma=prefix  try this for a non-standard install 
prefix of the oniguruma library
#  --with-pic[=PKGS]try to use only PIC/non-PIC objects 
[default=use both]
#  --with-sysroot[=DIR] Search for dependent libraries within 
DIR (or the compiler's sysroot if not specified).

PKG_NAMES="lib${NAME}1 lib${NAME}-devel $NAME"


libjq1_CATEGORY="Libs"
libjq1_CONTENTS="usr/bin/cyg${NAME}-1.dll"


libjq_devel_CATEGORY="Devel"
libjq_devel_CONTENTS="
usr/include/
usr/lib/lib${NAME}.dll.a
usr/lib/pkgconfig/libjq.pc
"


jq_CONTENTS="usr/bin/${NAME}.exe usr/share/doc/ usr/share/man/"


src_test() {
cd $B/
# did something change in libtool-2.4.5+?
PATH="$B/.libs:$PATH" cygmake check
}


# SPDX-License-Identifier: MIT AND CC-BY-3.0 AND dtoa AND ICU
LICENSE_SPDX="SPDX-License-Identifier: MIT AND CC-BY-3.0 AND dtoa AND ICU"
LICENSE="MIT AND CC-BY-3.0 AND dtoa AND ICU"
LICENSE_URI=COPYING

--- 

Re: [PATCH 0/4] Testsuite update

2023-08-08 Thread Corinna Vinschen via Cygwin-apps
On Aug  8 17:02, Jon Turney via Cygwin-apps wrote:
> On 07/08/2023 09:55, Corinna Vinschen wrote:
> > On Aug  4 13:47, Jon Turney wrote:
> > > This gets us down to no permanent failures in the testsuite in CI.
> 
> There is an intermittent failure in kill01, which I need to do something
> about before turning on taking notice of the testsuite result in CI.
> 
> Effectively, all this does is:
> 
>   pid = fork();
>   if (pid == 0) {
> pause();
>   } else {
> kill(pid, SIGKILL);
> waitpid(pid, , 0);
>   }
> 
> This is quite easy to demonstrate with 'winsup.api/ltp/kill01 -i 1000',
> which repeats the test, succeeding until it hangs.
> 
> Looking at the strace output, I would guess it's some race condition where a
> child process isn't yet in a position to receive a signal immediately after
> fork() returns in the parent (so the signal is dropped, and the parent
> blocks indefinitely in waitpid waiting for the child to terminate)
> 
> I'm not sure if that's fixable (or worth effort), so maybe just adding a
> small delay in the test is the thing to do... :)

It might be worth looking into it to make this more reliable, but the
patch is fine for the time being, of course.


Thanks,
Corinna


Re: [PATCH rebase] rebase: Add -c, --checksum option

2023-08-08 Thread Corinna Vinschen via Cygwin-apps
On Aug  8 12:10, Christian Franke via Cygwin-apps wrote:
> Last patch for now.
> 
> Left for later: ReBaseImage64() unconditionally updates the timestamp in the
> file header.
> 
> -- 
> Regards,
> Christian
> 

> From 3973a92cf11056521552d9d3f87efe8e721e8c31 Mon Sep 17 00:00:00 2001
> From: Christian Franke 
> Date: Tue, 8 Aug 2023 12:04:25 +0200
> Subject: [PATCH] rebase: Add -c, --checksum option
> 
> If specified, the file checksum in the PE header is updated after
> rebasing.
> 
> Signed-off-by: Christian Franke 
> ---
>  Makefile.in |  4 ++--
>  rebase.c| 50 ++
>  2 files changed, 48 insertions(+), 6 deletions(-)

Pushed.  Next release gets created right now.


Thanks,
Corinna



Re: [PATCH rebase] Add missing pechecksum.* to SRC_DISTFILES

2023-08-08 Thread Corinna Vinschen via Cygwin-apps
On Aug  8 10:54, Christian Franke via Cygwin-apps wrote:
> Missed yesterday, sorry.
> 
> -- 
> Regards,
> Christian
> 

> From 84065da466d9501d0522af8860ea829ee51c12f5 Mon Sep 17 00:00:00 2001
> From: Christian Franke 
> Date: Tue, 8 Aug 2023 10:52:14 +0200
> Subject: [PATCH] Add missing pechecksum.* to SRC_DISTFILES
> 
> Signed-off-by: Christian Franke 
> ---
>  Makefile.in | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile.in b/Makefile.in
> index 46df1d5..adb7972 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -84,7 +84,8 @@ PEFLAGS_OBJS = peflags.$(O) pechecksum.$(O) $(LIBOBJS)
>  PEFLAGS_LIBS =
>  
>  SRC_DISTFILES = configure.ac configure Makefile.in \
> - peflagsall.in rebaseall.in peflags.c rebase.c \
> + peflagsall.in rebaseall.in \
> + pechecksum.c pechecksum.h peflags.c rebase.c \
>   build.sh ChangeLog COPYING NEWS README setup.hint Todo \
>   build-aux/config.guess build-aux/config.sub \
>   build-aux/install-sh getopt.h_ getopt_long.c \
> -- 
> 2.39.0
> 


Pushed.


Thanks,
Corinna


Re: cygport cygautoreconf failure with AC_CONFIG_MACRO_DIRS

2023-08-08 Thread Jon Turney via Cygwin-apps

On 03/08/2023 17:21, Brian Inglis via Cygwin-apps wrote:

Hi folks,

Trying to build updated jq package, get cygautoreconf directory creation 
and existence bugs.

[...]


Cygport dies processing AC_CONFIG_SUBDIRS([modules/oniguruma]) under two 
levels of AS_IF (which handle existence of oniguruma library module or 
libonig-devel at default or custom locations with or without configure 
scripts in configure.ac) with:


Could not find modules/oniguruma/configure.ac or 
modules/oniguruma/configure.in


I'm not able to reproduce this problem.

Can you provide the jq.cygport you are using.

Also, can you be clear as to whether you have libonig-devel installed or 
not?




Re: [PATCH 0/4] Testsuite update

2023-08-08 Thread Jon Turney via Cygwin-apps

On 07/08/2023 09:55, Corinna Vinschen wrote:

On Aug  4 13:47, Jon Turney wrote:

This gets us down to no permanent failures in the testsuite in CI.


There is an intermittent failure in kill01, which I need to do something 
about before turning on taking notice of the testsuite result in CI.


Effectively, all this does is:

  pid = fork();
  if (pid == 0) {
pause();
  } else {
kill(pid, SIGKILL);
waitpid(pid, , 0);
  }

This is quite easy to demonstrate with 'winsup.api/ltp/kill01 -i 1000', 
which repeats the test, succeeding until it hangs.


Looking at the strace output, I would guess it's some race condition 
where a child process isn't yet in a position to receive a signal 
immediately after fork() returns in the parent (so the signal is 
dropped, and the parent blocks indefinitely in waitpid waiting for the 
child to terminate)


I'm not sure if that's fixable (or worth effort), so maybe just adding a 
small delay in the test is the thing to do... :)
From 3b7d7ae0f3c29de4d8e7ff0d4487bc6f7913dc86 Mon Sep 17 00:00:00 2001
From: Jon Turney 
Date: Tue, 8 Aug 2023 16:38:20 +0100
Subject: [PATCH] Cygwin: testsuite: Add a small delay in kill01

Avoid transient failures by adding a small delay after fork()-ing to
allow the child to get into a state where it can recieve signals.
---
 winsup/testsuite/winsup.api/ltp/kill01.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/winsup/testsuite/winsup.api/ltp/kill01.c 
b/winsup/testsuite/winsup.api/ltp/kill01.c
index 042899173..58053eeb8 100644
--- a/winsup/testsuite/winsup.api/ltp/kill01.c
+++ b/winsup/testsuite/winsup.api/ltp/kill01.c
@@ -102,6 +102,7 @@ main(int ac, char **av)
/*NOTREACHED*/
exit(exno);
} else {
+   Sleep(1);
TEST(kill(pid, TEST_SIG));
waitpid(pid, , 0);
}
-- 
2.39.0



Re: [PATCH rebase] rebase: Add -c, --checksum option

2023-08-08 Thread Christian Franke via Cygwin-apps

Jon Turney wrote:

On 08/08/2023 11:10, Christian Franke via Cygwin-apps wrote:

Last patch for now.

Left for later: ReBaseImage64() unconditionally updates the timestamp 
in the file header.


Just for clarity: does this mean that rebasing as it is currently 
implemented leaves the PE file with an invalid checksum, and the 
Windows loader is just fine this that?


Or is there something else happening which makes the checksum wrong?




Both rebase and peflags leave the PE file with an invalid checksum.

This is no problem for Cygwin uses cases:
"Checksums are required for kernel-mode drivers and some system DLLs."
https://learn.microsoft.com/en-us/windows/win32/api/imagehlp/nf-imagehlp-mapfileandchecksuma

--
Regards,
Christian



Re: [PATCH rebase] rebase: Add -c, --checksum option

2023-08-08 Thread Jon Turney via Cygwin-apps

On 08/08/2023 11:10, Christian Franke via Cygwin-apps wrote:

Last patch for now.

Left for later: ReBaseImage64() unconditionally updates the timestamp in 
the file header.


Just for clarity: does this mean that rebasing as it is currently 
implemented leaves the PE file with an invalid checksum, and the Windows 
loader is just fine this that?


Or is there something else happening which makes the checksum wrong?



[PATCH rebase] rebase: Add -c, --checksum option

2023-08-08 Thread Christian Franke via Cygwin-apps

Last patch for now.

Left for later: ReBaseImage64() unconditionally updates the timestamp in 
the file header.


--
Regards,
Christian

From 3973a92cf11056521552d9d3f87efe8e721e8c31 Mon Sep 17 00:00:00 2001
From: Christian Franke 
Date: Tue, 8 Aug 2023 12:04:25 +0200
Subject: [PATCH] rebase: Add -c, --checksum option

If specified, the file checksum in the PE header is updated after
rebasing.

Signed-off-by: Christian Franke 
---
 Makefile.in |  4 ++--
 rebase.c| 50 ++
 2 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index adb7972..2f061ca 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -74,7 +74,7 @@ override CXX_LDFLAGS+=@EXTRA_CXX_LDFLAG_OVERRIDES@
 
 LIBIMAGEHELPER = imagehelper/libimagehelper.a
 
-REBASE_OBJS = rebase.$(O) rebase-db.$(O) $(LIBOBJS)
+REBASE_OBJS = rebase.$(O) rebase-db.$(O) pechecksum.$(O) $(LIBOBJS)
 REBASE_LIBS = $(LIBIMAGEHELPER)
 
 REBASE_DUMP_OBJS = rebase-dump.$(O) rebase-db.$(O) $(LIBOBJS)
@@ -100,7 +100,7 @@ $(LIBIMAGEHELPER):
 rebase$(EXEEXT): $(REBASE_LIBS) $(REBASE_OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXX_LDFLAGS) -o $@ $(REBASE_OBJS) 
$(REBASE_LIBS)
 
-rebase.$(O):: rebase.c rebase-db.h Makefile
+rebase.$(O):: rebase.c pechecksum.h rebase-db.h Makefile
 
 rebase-db.$(O):: rebase-db.c rebase-db.h Makefile
 
diff --git a/rebase.c b/rebase.c
index 7417d4d..50cc79f 100644
--- a/rebase.c
+++ b/rebase.c
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include "imagehelper.h"
+#include "pechecksum.h"
 #include "rebase-db.h"
 #include  /* requires  */
 
@@ -74,6 +75,7 @@ WORD machine = IMAGE_FILE_MACHINE_I386;
 ULONG64 image_base = 0;
 ULONG64 low_addr;
 BOOL down_flag = FALSE;
+BOOL checksum_flag = FALSE;
 BOOL image_info_flag = FALSE;
 BOOL image_storage_flag = FALSE;
 BOOL image_oblivious_flag = FALSE;
@@ -1188,6 +1190,32 @@ print_overlapped ()
 }
 }
 
+static BOOL
+update_checksum (const char *pathname)
+{
+  int fd, err;
+  unsigned old_checksum, new_checksum;
+
+  if ((fd = open (pathname, O_RDWR | O_BINARY)) == -1)
+{
+  fprintf (stderr, "%s: failed to reopen for checksum update: %s\n",
+  pathname, strerror (errno));
+  return FALSE;
+}
+  new_checksum = pe32_checksum (fd, 1, _checksum);
+  err = errno;
+  close(fd);
+  if (!new_checksum)
+{
+  fprintf (stderr, "%s: checksum update failed: %s\n", pathname,
+  strerror (err));
+  /* Assume file is unchanged. */
+  return FALSE;
+}
+
+  return (new_checksum != old_checksum);
+}
+
 BOOL
 rebase (const char *pathname, ULONG64 *new_image_base, BOOL down_flag)
 {
@@ -1279,13 +1307,18 @@ retry:
 }
 #endif
 
+  /* Update checksum, if requested. */
+  status = (checksum_flag ? update_checksum (pathname) : FALSE);
+
   /* Display rebase results, if verbose. */
   if (verbose)
 {
-  printf ("%s: new base = %" PRIx64 ", new size = %x\n",
+  printf ("%s: new base = %" PRIx64 ", new size = %x%s\n",
  pathname,
  (uint64_t) ((down_flag) ? *new_image_base : prev_new_image_base),
- (uint32_t) (new_image_size + offset));
+ (uint32_t) (new_image_size + offset),
+ (checksum_flag ? (status ? ", checksum updated" :
+ ", checksum unchanged") : ""));
 }
 
   /* Calculate next base address, if rebasing up. */
@@ -1299,6 +1332,7 @@ static struct option long_options[] = {
   {"32",   no_argument,   NULL, '4'},
   {"64",   no_argument,   NULL, '8'},
   {"base", required_argument, NULL, 'b'},
+  {"checksum", no_argument,   NULL, 'c'},
   {"down", no_argument,   NULL, 'd'},
   {"help", no_argument,   NULL, 'h'},
   {"usage",no_argument,   NULL, 'h'},
@@ -1316,7 +1350,7 @@ static struct option long_options[] = {
   {NULL,   no_argument,   NULL,  0 }
 };
 
-static const char *short_options = "48b:dhiMno:OqstT:vV";
+static const char *short_options = "48b:cdhiMno:OqstT:vV";
 
 void
 parse_args (int argc, char *argv[])
@@ -1341,6 +1375,9 @@ parse_args (int argc, char *argv[])
  image_base = string_to_ulonglong (optarg);
  force_rebase_flag = TRUE;
  break;
+   case 'c':
+ checksum_flag = TRUE;
+ break;
case 'd':
  down_flag = TRUE;
  break;
@@ -1625,6 +1662,10 @@ Rebase PE files, usually DLLs, to a specified address or 
address range.\n\
   One of the options -b, -s or -i is mandatory.  If no rebase database 
exists\n\
   yet, -b is required together with -s.\n\
 \n\
+  -c, --checksum  Update the file's checksum in the PE header if the\n\
+  file has been successfully rebased.  This also 
bumps\n\
+  the file's modification time (like -t) if the\n\
+  checksum has been changed.\n\
   -d, --down  Treat the BaseAddress as upper ceiling and rebase\n\
   files top-down from 

Re: [PATCH rebase] peflags: Fix ULONG range checks

2023-08-08 Thread Corinna Vinschen via Cygwin-apps
On Aug  8 10:40, Christian Franke via Cygwin-apps wrote:
> Corinna Vinschen wrote:
> > On Aug  8 10:06, Christian Franke via Cygwin-apps wrote:
> > > Corinna Vinschen via Cygwin-apps wrote:
> > > > Hi Christian,
> > > > 
> > > > On Aug  7 16:07, Christian Franke via Cygwin-apps wrote:
> > > > > Minor issue found during tests of the upcoming 'peflags --timestamp' 
> > > > > patch.
> > > > > 
> > > > > -- 
> > > > > Regards,
> > > > > Christian
> > > > > 
> > > > > ...
> > > > > diff --git a/peflags.c b/peflags.c
> > > > > index 93eaa0b..d98b121 100644
> > > > > --- a/peflags.c
> > > > > +++ b/peflags.c
> > > > > @@ -30,7 +30,6 @@
> > > > >#include 
> > > > >#include 
> > > > >#include 
> > > > > -#include 
> > > > >#if defined (__CYGWIN__) || defined (__MSYS__)
> > > > >#include 
> > > > >#endif
> > > > > @@ -598,7 +597,7 @@ handle_num_option (const char *option_name,
> > > > >  || sizeof_vals[option_index].value > 0xULL
> > > > >  /* Just a ULONG value */
> > > > >  || (sizeof_vals[option_index].is_ulong
> > > > > -&& sizeof_vals[option_index].value > ULONG_MAX))
> > > > > +&& sizeof_vals[option_index].value > 
> > > > > 0xULL))
> > > > What about using MAXDWORD or MAXULONG32 instead?
> > > Of course :-)
> > > 
> > > Christian
> > > 
> > Pushed.  I've started deploying a new release.
> 
> I'm currently working on 'rebase -c, --checksum' and found one minor issue:
> pechecksum.* are missing in SRC_DISTFILES.

Ok, I stopped the deployment.  Are you going to send fixes?


Corinna


[PATCH rebase] Add missing pechecksum.* to SRC_DISTFILES

2023-08-08 Thread Christian Franke via Cygwin-apps

Missed yesterday, sorry.

--
Regards,
Christian

From 84065da466d9501d0522af8860ea829ee51c12f5 Mon Sep 17 00:00:00 2001
From: Christian Franke 
Date: Tue, 8 Aug 2023 10:52:14 +0200
Subject: [PATCH] Add missing pechecksum.* to SRC_DISTFILES

Signed-off-by: Christian Franke 
---
 Makefile.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in
index 46df1d5..adb7972 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -84,7 +84,8 @@ PEFLAGS_OBJS = peflags.$(O) pechecksum.$(O) $(LIBOBJS)
 PEFLAGS_LIBS =
 
 SRC_DISTFILES = configure.ac configure Makefile.in \
-   peflagsall.in rebaseall.in peflags.c rebase.c \
+   peflagsall.in rebaseall.in \
+   pechecksum.c pechecksum.h peflags.c rebase.c \
build.sh ChangeLog COPYING NEWS README setup.hint Todo \
build-aux/config.guess build-aux/config.sub \
build-aux/install-sh getopt.h_ getopt_long.c \
-- 
2.39.0



Re: [PATCH rebase] peflags: Fix ULONG range checks

2023-08-08 Thread Christian Franke via Cygwin-apps

Corinna Vinschen wrote:

On Aug  8 10:06, Christian Franke via Cygwin-apps wrote:

Corinna Vinschen via Cygwin-apps wrote:

Hi Christian,

On Aug  7 16:07, Christian Franke via Cygwin-apps wrote:

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

--
Regards,
Christian

...
diff --git a/peflags.c b/peflags.c
index 93eaa0b..d98b121 100644
--- a/peflags.c
+++ b/peflags.c
@@ -30,7 +30,6 @@
   #include 
   #include 
   #include 
-#include 
   #if defined (__CYGWIN__) || defined (__MSYS__)
   #include 
   #endif
@@ -598,7 +597,7 @@ handle_num_option (const char *option_name,
   || sizeof_vals[option_index].value > 0xULL
   /* Just a ULONG value */
   || (sizeof_vals[option_index].is_ulong
-  && sizeof_vals[option_index].value > ULONG_MAX))
+  && sizeof_vals[option_index].value > 0xULL))

What about using MAXDWORD or MAXULONG32 instead?

Of course :-)

Christian


Pushed.  I've started deploying a new release.


I'm currently working on 'rebase -c, --checksum' and found one minor 
issue: pechecksum.* are missing in SRC_DISTFILES.




Re: [PATCH rebase] peflags: Fix ULONG range checks

2023-08-08 Thread Corinna Vinschen via Cygwin-apps
On Aug  8 10:06, Christian Franke via Cygwin-apps wrote:
> Corinna Vinschen via Cygwin-apps wrote:
> > Hi Christian,
> > 
> > On Aug  7 16:07, Christian Franke via Cygwin-apps wrote:
> > > Minor issue found during tests of the upcoming 'peflags --timestamp' 
> > > patch.
> > > 
> > > -- 
> > > Regards,
> > > Christian
> > > 
> > > ...
> > > diff --git a/peflags.c b/peflags.c
> > > index 93eaa0b..d98b121 100644
> > > --- a/peflags.c
> > > +++ b/peflags.c
> > > @@ -30,7 +30,6 @@
> > >   #include 
> > >   #include 
> > >   #include 
> > > -#include 
> > >   #if defined (__CYGWIN__) || defined (__MSYS__)
> > >   #include 
> > >   #endif
> > > @@ -598,7 +597,7 @@ handle_num_option (const char *option_name,
> > >  || sizeof_vals[option_index].value > 0xULL
> > >  /* Just a ULONG value */
> > >  || (sizeof_vals[option_index].is_ulong
> > > -&& sizeof_vals[option_index].value > ULONG_MAX))
> > > +&& sizeof_vals[option_index].value > 0xULL))
> > What about using MAXDWORD or MAXULONG32 instead?
> 
> Of course :-)
> 
> Christian
> 

Pushed.  I've started deploying a new release.


Thanks!
Corinna


Re: [PATCH rebase] peflags: Fix ULONG range checks

2023-08-08 Thread Christian Franke via Cygwin-apps

Corinna Vinschen via Cygwin-apps wrote:

Hi Christian,

On Aug  7 16:07, Christian Franke via Cygwin-apps wrote:

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

--
Regards,
Christian

...
diff --git a/peflags.c b/peflags.c
index 93eaa0b..d98b121 100644
--- a/peflags.c
+++ b/peflags.c
@@ -30,7 +30,6 @@
  #include 
  #include 
  #include 
-#include 
  #if defined (__CYGWIN__) || defined (__MSYS__)
  #include 
  #endif
@@ -598,7 +597,7 @@ handle_num_option (const char *option_name,
   || sizeof_vals[option_index].value > 0xULL
   /* Just a ULONG value */
   || (sizeof_vals[option_index].is_ulong
-  && sizeof_vals[option_index].value > ULONG_MAX))
+  && sizeof_vals[option_index].value > 0xULL))

What about using MAXDWORD or MAXULONG32 instead?


Of course :-)

Christian

From 8c8537fbc08d677651eee3055e5b0c6c9873804d Mon Sep 17 00:00:00 2001
From: Christian Franke 
Date: Tue, 8 Aug 2023 09:58:39 +0200
Subject: [PATCH] peflags: Fix ULONG range checks

Don't use ULONG_MAX from  because ULONG is not necessarily
'unsigned long'.  Use MAXULONG32 instead.

Signed-off-by: Christian Franke 
---
 peflags.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/peflags.c b/peflags.c
index f215704..1a61da7 100644
--- a/peflags.c
+++ b/peflags.c
@@ -30,7 +30,6 @@
 #include 
 #include 
 #include 
-#include 
 #if defined (__CYGWIN__) || defined (__MSYS__)
 #include 
 #endif
@@ -696,7 +695,7 @@ handle_num_option (const char *option_name,
   || sizeof_vals[option_index].value > 0xULL
   /* Just a ULONG value */
   || (sizeof_vals[option_index].is_ulong
-  && sizeof_vals[option_index].value > ULONG_MAX))
+  && sizeof_vals[option_index].value > MAXULONG32))
 {
   fprintf (stderr, "Invalid argument for %s: %s\n", 
   option_name, option_arg);
@@ -1092,7 +1091,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 > MAXULONG32)
{
  fprintf (stderr, "%s: Skip writing %s, value too big\n",
   pep->pathname, val->name);
-- 
2.39.0