diff mbox series

createrepo-c: Fix 32 bit architecture segfaults with 64 bit time

Message ID 20230726195044.1453294-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit a5137a5c5c03a728faf57fd335ca8378f4f4cb91
Headers show
Series createrepo-c: Fix 32 bit architecture segfaults with 64 bit time | expand

Commit Message

Richard Purdie July 26, 2023, 7:50 p.m. UTC
After including time64.inc, createrepo-c was segfaulting on 32 bit architectures
when creating repo indexes (even for an empty repo).

Add a patch from Khem to fix this and some other compiler warnings related to 64
bit time on 32 bit.

[YOCTO #15170]

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 .../createrepo-c/createrepo-c/time64fix.patch | 69 +++++++++++++++++++
 .../createrepo-c/createrepo-c_0.21.1.bb       |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644 meta/recipes-devtools/createrepo-c/createrepo-c/time64fix.patch

Comments

Khem Raj July 26, 2023, 9:53 p.m. UTC | #1
On Wed, Jul 26, 2023 at 12:50 PM Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
>
> After including time64.inc, createrepo-c was segfaulting on 32 bit architectures
> when creating repo indexes (even for an empty repo).
>
> Add a patch from Khem to fix this and some other compiler warnings related to 64
> bit time on 32 bit.
>
> [YOCTO #15170]
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
>  .../createrepo-c/createrepo-c/time64fix.patch | 69 +++++++++++++++++++
>  .../createrepo-c/createrepo-c_0.21.1.bb       |  1 +
>  2 files changed, 70 insertions(+)
>  create mode 100644 meta/recipes-devtools/createrepo-c/createrepo-c/time64fix.patch
>
> diff --git a/meta/recipes-devtools/createrepo-c/createrepo-c/time64fix.patch b/meta/recipes-devtools/createrepo-c/createrepo-c/time64fix.patch
> new file mode 100644
> index 00000000000..d022d95b703
> --- /dev/null
> +++ b/meta/recipes-devtools/createrepo-c/createrepo-c/time64fix.patch
> @@ -0,0 +1,69 @@
> +From 89e1c9415fb8438310036d5810cdb7da75ee3a7f Mon Sep 17 00:00:00 2001
> +From: Khem Raj <raj.khem@gmail.com>
> +Date: Wed, 26 Jul 2023 12:27:14 -0700
> +Subject: [PATCH] Adjust printf formats for 64bit time_t on 32bit systems
> +
> +Fixes format specifier mismatch warnings as well while here
> +
> +e.g.
> +warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'time_t'
> +
> +Upstream-Status: Pending

Its also submitted upstream now so you may want to change the status
to Submitted [https://github.com/rpm-software-management/createrepo_c/pull/376]

> +
> +Signed-off-by: Khem Raj <raj.khem@gmail.com>
> +---
> + src/createrepo_c.c    | 4 ++--
> + src/misc.c            | 4 ++--
> + src/xml_dump_repomd.c | 2 +-
> + 3 files changed, 5 insertions(+), 5 deletions(-)
> +
> +diff --git a/src/createrepo_c.c b/src/createrepo_c.c
> +index 8681419..0f9048a 100644
> +--- a/src/createrepo_c.c
> ++++ b/src/createrepo_c.c
> +@@ -582,9 +582,9 @@ duplicates_warning(const char *nevra, GArray *locations, CmdDupNevra option)
> +   for (size_t i=0; i<locations->len; i++) {
> +       struct DuplicateLocation location = g_array_index(locations, struct
> +                                                         DuplicateLocation, i);
> +-      g_warning("    Sourced from location: \'%s\', build timestamp: %ld%s",
> ++      g_warning("    Sourced from location: \'%s\', build timestamp: %jd%s",
> +                 location.location,
> +-                location.pkg->time_build,
> ++                (intmax_t) location.pkg->time_build,
> +                 location.pkg->skip_dump ? skip_reason : "");
> +
> +   }
> +diff --git a/src/misc.c b/src/misc.c
> +index 8511ca2..7866c7b 100644
> +--- a/src/misc.c
> ++++ b/src/misc.c
> +@@ -1512,11 +1512,11 @@ cr_append_pid_and_datetime(const char *str, const char *suffix)
> +     gettimeofday(&tv, NULL);
> +     timeinfo = localtime (&(tv.tv_sec));
> +     strftime(datetime, 80, "%Y%m%d%H%M%S", timeinfo);
> +-    gchar *result = g_strdup_printf("%s%jd.%s.%ld%s",
> ++    gchar *result = g_strdup_printf("%s%jd.%s.%jd%s",
> +                                     str ? str : "",
> +                                     (intmax_t) getpid(),
> +                                     datetime,
> +-                                    tv.tv_usec,
> ++                                    (intmax_t) tv.tv_usec,
> +                                     suffix ? suffix : "");
> +     return result;
> + }
> +diff --git a/src/xml_dump_repomd.c b/src/xml_dump_repomd.c
> +index 33b0e09..9d24249 100644
> +--- a/src/xml_dump_repomd.c
> ++++ b/src/xml_dump_repomd.c
> +@@ -143,7 +143,7 @@ cr_xml_dump_repomd_body(xmlNodePtr root, cr_Repomd *repomd)
> +                            BAD_CAST repomd->revision);
> +     } else {
> +         // Use the current time if no revision was explicitly specified
> +-        gchar *rev = g_strdup_printf("%ld", time(NULL));
> ++        gchar *rev = g_strdup_printf("%jd", (intmax_t) time(NULL));
> +         xmlNewChild(root, NULL, BAD_CAST "revision", BAD_CAST rev);
> +         g_free(rev);
> +     }
> +--
> +2.41.0
> +
> diff --git a/meta/recipes-devtools/createrepo-c/createrepo-c_0.21.1.bb b/meta/recipes-devtools/createrepo-c/createrepo-c_0.21.1.bb
> index 5080131dc1e..57f23b8dfdb 100644
> --- a/meta/recipes-devtools/createrepo-c/createrepo-c_0.21.1.bb
> +++ b/meta/recipes-devtools/createrepo-c/createrepo-c_0.21.1.bb
> @@ -8,6 +8,7 @@ SRC_URI = "git://github.com/rpm-software-management/createrepo_c;branch=master;p
>             file://0001-Do-not-set-PYTHON_INSTALL_DIR-by-running-python.patch \
>             file://0001-include-rpm-rpmstring.h.patch \
>             file://0001-src-cmd_parser.c-add-a-missing-parameter-name.patch \
> +           file://time64fix.patch \
>             "
>
>  SRCREV = "0652d7303ce236e596c83c29ccc9bee7868fce6e"
> --
> 2.39.2
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#184901): https://lists.openembedded.org/g/openembedded-core/message/184901
> Mute This Topic: https://lists.openembedded.org/mt/100378249/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/meta/recipes-devtools/createrepo-c/createrepo-c/time64fix.patch b/meta/recipes-devtools/createrepo-c/createrepo-c/time64fix.patch
new file mode 100644
index 00000000000..d022d95b703
--- /dev/null
+++ b/meta/recipes-devtools/createrepo-c/createrepo-c/time64fix.patch
@@ -0,0 +1,69 @@ 
+From 89e1c9415fb8438310036d5810cdb7da75ee3a7f Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Wed, 26 Jul 2023 12:27:14 -0700
+Subject: [PATCH] Adjust printf formats for 64bit time_t on 32bit systems
+
+Fixes format specifier mismatch warnings as well while here
+
+e.g.
+warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'time_t'
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ src/createrepo_c.c    | 4 ++--
+ src/misc.c            | 4 ++--
+ src/xml_dump_repomd.c | 2 +-
+ 3 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/src/createrepo_c.c b/src/createrepo_c.c
+index 8681419..0f9048a 100644
+--- a/src/createrepo_c.c
++++ b/src/createrepo_c.c
+@@ -582,9 +582,9 @@ duplicates_warning(const char *nevra, GArray *locations, CmdDupNevra option)
+   for (size_t i=0; i<locations->len; i++) {
+       struct DuplicateLocation location = g_array_index(locations, struct
+                                                         DuplicateLocation, i);
+-      g_warning("    Sourced from location: \'%s\', build timestamp: %ld%s",
++      g_warning("    Sourced from location: \'%s\', build timestamp: %jd%s",
+                 location.location,
+-                location.pkg->time_build,
++                (intmax_t) location.pkg->time_build,
+                 location.pkg->skip_dump ? skip_reason : "");
+ 
+   }
+diff --git a/src/misc.c b/src/misc.c
+index 8511ca2..7866c7b 100644
+--- a/src/misc.c
++++ b/src/misc.c
+@@ -1512,11 +1512,11 @@ cr_append_pid_and_datetime(const char *str, const char *suffix)
+     gettimeofday(&tv, NULL);
+     timeinfo = localtime (&(tv.tv_sec));
+     strftime(datetime, 80, "%Y%m%d%H%M%S", timeinfo);
+-    gchar *result = g_strdup_printf("%s%jd.%s.%ld%s",
++    gchar *result = g_strdup_printf("%s%jd.%s.%jd%s",
+                                     str ? str : "",
+                                     (intmax_t) getpid(),
+                                     datetime,
+-                                    tv.tv_usec,
++                                    (intmax_t) tv.tv_usec,
+                                     suffix ? suffix : "");
+     return result;
+ }
+diff --git a/src/xml_dump_repomd.c b/src/xml_dump_repomd.c
+index 33b0e09..9d24249 100644
+--- a/src/xml_dump_repomd.c
++++ b/src/xml_dump_repomd.c
+@@ -143,7 +143,7 @@ cr_xml_dump_repomd_body(xmlNodePtr root, cr_Repomd *repomd)
+                            BAD_CAST repomd->revision);
+     } else {
+         // Use the current time if no revision was explicitly specified
+-        gchar *rev = g_strdup_printf("%ld", time(NULL));
++        gchar *rev = g_strdup_printf("%jd", (intmax_t) time(NULL));
+         xmlNewChild(root, NULL, BAD_CAST "revision", BAD_CAST rev);
+         g_free(rev);
+     }
+-- 
+2.41.0
+
diff --git a/meta/recipes-devtools/createrepo-c/createrepo-c_0.21.1.bb b/meta/recipes-devtools/createrepo-c/createrepo-c_0.21.1.bb
index 5080131dc1e..57f23b8dfdb 100644
--- a/meta/recipes-devtools/createrepo-c/createrepo-c_0.21.1.bb
+++ b/meta/recipes-devtools/createrepo-c/createrepo-c_0.21.1.bb
@@ -8,6 +8,7 @@  SRC_URI = "git://github.com/rpm-software-management/createrepo_c;branch=master;p
            file://0001-Do-not-set-PYTHON_INSTALL_DIR-by-running-python.patch \
            file://0001-include-rpm-rpmstring.h.patch \
            file://0001-src-cmd_parser.c-add-a-missing-parameter-name.patch \
+           file://time64fix.patch \
            "
 
 SRCREV = "0652d7303ce236e596c83c29ccc9bee7868fce6e"