diff mbox series

[1/3] systemd: Fix build with gcc8

Message ID 20180528155833.24224-1-raj.khem@gmail.com
State Accepted
Commit 6a3805f06cd7832d70d5b652ec1be612f5f027e6
Headers show
Series [1/3] systemd: Fix build with gcc8 | expand

Commit Message

Khem Raj May 28, 2018, 3:58 p.m. UTC
Signed-off-by: Khem Raj <raj.khem@gmail.com>

---
 ...ange-the-default-device-timeout-to-2.patch |   9 +-
 ...ation-compile-failure-by-typecasting.patch | 173 ++++++++++++++++++
 meta/recipes-core/systemd/systemd_237.bb      |   1 +
 3 files changed, 177 insertions(+), 6 deletions(-)
 create mode 100644 meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

-- 
2.17.0

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Comments

Martin Jansa May 31, 2018, 4:05 p.m. UTC | #1
Unlike the previous version you had in your RFT branch (which
added -Wno-error=format-truncation) this doesn't seem to be complete fix.

In qemux86 build which already includes this change I'm seeing:
../git/src/basic/time-util.c: In function 'format_timespan':
../git/src/basic/time-util.c:508:46: error: '%0*llu' directive output
between 1 and 2147483647 bytes may cause result to exceed 'INT_MAX'
[-Werror=format-truncation=]

"%s"USEC_FMT".%0*"PRI_USEC"%s",
                                              ^~~~
../git/src/basic/time-util.c:508:60: note: format string is defined here

"%s"USEC_FMT".%0*"PRI_USEC"%s",
../git/src/basic/time-util.c:508:46: note: directive argument in the range
[0, 18446744073709551614]

"%s"USEC_FMT".%0*"PRI_USEC"%s",
                                              ^~~~

And this part doesn't seem to be fixed upstream yet.

Cheers,

On Mon, May 28, 2018 at 5:58 PM Khem Raj <raj.khem@gmail.com> wrote:

> Signed-off-by: Khem Raj <raj.khem@gmail.com>

> ---

>  ...ange-the-default-device-timeout-to-2.patch |   9 +-

>  ...ation-compile-failure-by-typecasting.patch | 173 ++++++++++++++++++

>  meta/recipes-core/systemd/systemd_237.bb      |   1 +

>  3 files changed, 177 insertions(+), 6 deletions(-)

>  create mode 100644

> meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>

> diff --git

> a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

> b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

> index b7b1ea0886..98c83620ff 100644

> ---

> a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

> +++

> b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

> @@ -1,4 +1,4 @@

> -From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17 00:00:00 2001

> +From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17 00:00:00 2001

>  From: Khem Raj <raj.khem@gmail.com>

>  Date: Mon, 14 Dec 2015 04:09:19 +0000

>  Subject: [PATCH] core/device.c: Change the default device timeout to 240

> sec.

> @@ -16,10 +16,10 @@ Signed-off-by: Khem Raj <raj.khem@gmail.com>

>   1 file changed, 1 insertion(+), 1 deletion(-)

>

>  diff --git a/src/core/device.c b/src/core/device.c

> -index 77601c552..98bf49ba2 100644

> +index a43664d3b..4b16a8aec 100644

>  --- a/src/core/device.c

>  +++ b/src/core/device.c

> -@@ -112,7 +112,7 @@ static void device_init(Unit *u) {

> +@@ -113,7 +113,7 @@ static void device_init(Unit *u) {

>            * indefinitely for plugged in devices, something which cannot

>            * happen for the other units since their operations time out

>            * anyway. */

> @@ -28,6 +28,3 @@ index 77601c552..98bf49ba2 100644

>

>           u->ignore_on_isolate = true;

>   }

> ---

> -2.16.1

> -

> diff --git

> a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

> b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

> new file mode 100644

> index 0000000000..e56061f41b

> --- /dev/null

> +++

> b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

> @@ -0,0 +1,173 @@

> +From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17 00:00:00 2001

> +From: Patrick Uiterwijk <patrick@puiterwijk.org>

> +Date: Thu, 22 Feb 2018 19:41:30 +0100

> +Subject: [PATCH] Fix format-truncation compile failure by typecasting USB

> IDs

> + (#8250)

> +

> +This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit

> int, and

> +uses that for parsing USB device and vendor IDs.

> +

> +This fixes a compile error with gcc-8 because while we know that USB IDs

> are 2 bytes,

> +the compiler does not know that.

> +

> +../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may

> be

> +truncated writing between 4 and 8 bytes into a region of size between 2

> and 6

> +[-Werror=format-truncation=]

> +

> +Upstream-Status: Backport [

> https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd

> ]

> +

> +Signed-off-by: Adam Williamson <awilliam@redhat.com>

> +Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>

> +---

> + src/basic/parse-util.c       | 24 ++++++++++++++++++++++

> + src/basic/parse-util.h       |  2 ++

> + src/test/test-parse-util.c   | 39 ++++++++++++++++++++++++++++++++++++

> + src/udev/udev-builtin-hwdb.c | 13 ++++++------

> + 4 files changed, 71 insertions(+), 7 deletions(-)

> +

> +diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c

> +index 97533721d..ff3fc298a 100644

> +--- a/src/basic/parse-util.c

> ++++ b/src/basic/parse-util.c

> +@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {

> +         return 0;

> + }

> +

> ++int safe_atoux16(const char *s, uint16_t *ret) {

> ++        char *x = NULL;

> ++        unsigned long l;

> ++

> ++        assert(s);

> ++        assert(ret);

> ++

> ++        s += strspn(s, WHITESPACE);

> ++

> ++        errno = 0;

> ++        l = strtoul(s, &x, 16);

> ++        if (errno > 0)

> ++                return -errno;

> ++        if (!x || x == s || *x != 0)

> ++                return -EINVAL;

> ++        if (s[0] == '-')

> ++                return -ERANGE;

> ++        if ((unsigned long) (uint16_t) l != l)

> ++                return -ERANGE;

> ++

> ++        *ret = (uint16_t) l;

> ++        return 0;

> ++}

> ++

> + int safe_atod(const char *s, double *ret_d) {

> +         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;

> +         char *x = NULL;

> +diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h

> +index 1eda1d7f9..727422056 100644

> +--- a/src/basic/parse-util.h

> ++++ b/src/basic/parse-util.h

> +@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);

> + int safe_atou16(const char *s, uint16_t *ret);

> + int safe_atoi16(const char *s, int16_t *ret);

> +

> ++int safe_atoux16(const char *s, uint16_t *ret);

> ++

> + static inline int safe_atou32(const char *s, uint32_t *ret_u) {

> +         assert_cc(sizeof(uint32_t) == sizeof(unsigned));

> +         return safe_atou(s, (unsigned*) ret_u);

> +diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c

> +index 937500213..a99cea5a1 100644

> +--- a/src/test/test-parse-util.c

> ++++ b/src/test/test-parse-util.c

> +@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {

> +         assert_se(r == -EINVAL);

> + }

> +

> ++static void test_safe_atoux16(void) {

> ++        int r;

> ++        uint16_t l;

> ++

> ++        r = safe_atoux16("1234", &l);

> ++        assert_se(r == 0);

> ++        assert_se(l == 0x1234);

> ++

> ++        r = safe_atoux16("abcd", &l);

> ++        assert_se(r == 0);

> ++        assert_se(l == 0xabcd);

> ++

> ++        r = safe_atoux16("  1234", &l);

> ++        assert_se(r == 0);

> ++        assert_se(l == 0x1234);

> ++

> ++        r = safe_atoux16("12345", &l);

> ++        assert_se(r == -ERANGE);

> ++

> ++        r = safe_atoux16("-1", &l);

> ++        assert_se(r == -ERANGE);

> ++

> ++        r = safe_atoux16("  -1", &l);

> ++        assert_se(r == -ERANGE);

> ++

> ++        r = safe_atoux16("junk", &l);

> ++        assert_se(r == -EINVAL);

> ++

> ++        r = safe_atoux16("123x", &l);

> ++        assert_se(r == -EINVAL);

> ++

> ++        r = safe_atoux16("12.3", &l);

> ++        assert_se(r == -EINVAL);

> ++

> ++        r = safe_atoux16("", &l);

> ++        assert_se(r == -EINVAL);

> ++}

> ++

> + static void test_safe_atou64(void) {

> +         int r;

> +         uint64_t l;

> +@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {

> +         test_safe_atolli();

> +         test_safe_atou16();

> +         test_safe_atoi16();

> ++        test_safe_atoux16();

> +         test_safe_atou64();

> +         test_safe_atoi64();

> +         test_safe_atod();

> +diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c

> +index ca7f7c230..dbfe02429 100644

> +--- a/src/udev/udev-builtin-hwdb.c

> ++++ b/src/udev/udev-builtin-hwdb.c

> +@@ -27,6 +27,7 @@

> +

> + #include "alloc-util.h"

> + #include "hwdb-util.h"

> ++#include "parse-util.h"

> + #include "string-util.h"

> + #include "udev-util.h"

> + #include "udev.h"

> +@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev,

> +

> + static const char *modalias_usb(struct udev_device *dev, char *s, size_t

> size) {

> +         const char *v, *p;

> +-        int vn, pn;

> ++        uint16_t vn, pn;

> +

> +         v = udev_device_get_sysattr_value(dev, "idVendor");

> +         if (!v)

> +@@ -71,12 +72,10 @@ static const char *modalias_usb(struct udev_device

> *dev, char *s, size_t size) {

> +         p = udev_device_get_sysattr_value(dev, "idProduct");

> +         if (!p)

> +                 return NULL;

> +-        vn = strtol(v, NULL, 16);

> +-        if (vn <= 0)

> +-                return NULL;

> +-        pn = strtol(p, NULL, 16);

> +-        if (pn <= 0)

> +-                return NULL;

> ++        if (safe_atoux16(v, &vn) < 0)

> ++              return NULL;

> ++        if (safe_atoux16(p, &pn) < 0)

> ++              return NULL;

> +         snprintf(s, size, "usb:v%04Xp%04X*", vn, pn);

> +         return s;

> + }

> +--

> +2.17.0

> +

> diff --git a/meta/recipes-core/systemd/systemd_237.bb

> b/meta/recipes-core/systemd/systemd_237.bb

> index b7c2113255..c4743a6b9d 100644

> --- a/meta/recipes-core/systemd/systemd_237.bb

> +++ b/meta/recipes-core/systemd/systemd_237.bb

> @@ -52,6 +52,7 @@ SRC_URI += "file://touchscreen.rules \

>             file://0032-memfd.patch \

>

> file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \

>             file://libmount.patch \

> +

>  file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \

>             "

>  SRC_URI_append_qemuall = "

> file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"

>

> --

> 2.17.0

>

> --

> _______________________________________________

> Openembedded-core mailing list

> Openembedded-core@lists.openembedded.org

> http://lists.openembedded.org/mailman/listinfo/openembedded-core

>
<div dir="ltr">Unlike the previous version you had in your RFT branch (which added -Wno-error=format-truncation) this doesn&#39;t seem to be complete fix.<div><br></div><div>In qemux86 build which already includes this change I&#39;m seeing:</div><div><div>../git/src/basic/time-util.c: In function &#39;format_timespan&#39;:</div><div>../git/src/basic/time-util.c:508:46: error: &#39;%0*llu&#39; directive output between 1 and 2147483647 bytes may cause result to exceed &#39;INT_MAX&#39; [-Werror=format-truncation=]</div><div>                                              &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,</div><div>                                              ^~~~</div><div>../git/src/basic/time-util.c:508:60: note: format string is defined here</div><div>                                              &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,</div><div>../git/src/basic/time-util.c:508:46: note: directive argument in the range [0, 18446744073709551614]</div><div>                                              &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,</div><div>                                              ^~~~</div></div><div><br></div><div>And this part doesn&#39;t seem to be fixed upstream yet.</div><div><br></div><div>Cheers,</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, May 28, 2018 at 5:58 PM Khem Raj &lt;<a href="mailto:raj.khem@gmail.com">raj.khem@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
---<br>
 ...ange-the-default-device-timeout-to-2.patch |   9 +-<br>
 ...ation-compile-failure-by-typecasting.patch | 173 ++++++++++++++++++<br>
 meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a>      |   1 +<br>
 3 files changed, 177 insertions(+), 6 deletions(-)<br>
 create mode 100644 meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
<br>
diff --git a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
index b7b1ea0886..98c83620ff 100644<br>
--- a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
+++ b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
@@ -1,4 +1,4 @@<br>
-From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17 00:00:00 2001<br>
+From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17 00:00:00 2001<br>
 From: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
 Date: Mon, 14 Dec 2015 04:09:19 +0000<br>
 Subject: [PATCH] core/device.c: Change the default device timeout to 240 sec.<br>
@@ -16,10 +16,10 @@ Signed-off-by: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
  1 file changed, 1 insertion(+), 1 deletion(-)<br>
<br>
 diff --git a/src/core/device.c b/src/core/device.c<br>
-index 77601c552..98bf49ba2 100644<br>
+index a43664d3b..4b16a8aec 100644<br>
 --- a/src/core/device.c<br>
 +++ b/src/core/device.c<br>
-@@ -112,7 +112,7 @@ static void device_init(Unit *u) {<br>
+@@ -113,7 +113,7 @@ static void device_init(Unit *u) {<br>
           * indefinitely for plugged in devices, something which cannot<br>
           * happen for the other units since their operations time out<br>
           * anyway. */<br>
@@ -28,6 +28,3 @@ index 77601c552..98bf49ba2 100644<br>
<br>
          u-&gt;ignore_on_isolate = true;<br>
  }<br>
--- <br>
-2.16.1<br>
-<br>
diff --git a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
new file mode 100644<br>
index 0000000000..e56061f41b<br>
--- /dev/null<br>
+++ b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
@@ -0,0 +1,173 @@<br>
+From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17 00:00:00 2001<br>
+From: Patrick Uiterwijk &lt;<a href="mailto:patrick@puiterwijk.org" target="_blank">patrick@puiterwijk.org</a>&gt;<br>
+Date: Thu, 22 Feb 2018 19:41:30 +0100<br>
+Subject: [PATCH] Fix format-truncation compile failure by typecasting USB IDs<br>
+ (#8250)<br>
+<br>
+This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit int, and<br>
+uses that for parsing USB device and vendor IDs.<br>
+<br>
+This fixes a compile error with gcc-8 because while we know that USB IDs are 2 bytes,<br>
+the compiler does not know that.<br>
+<br>
+../src/udev/udev-builtin-hwdb.c:80:38: error: &#39;%04X&#39; directive output may be<br>
+truncated writing between 4 and 8 bytes into a region of size between 2 and 6<br>
+[-Werror=format-truncation=]<br>
+<br>
+Upstream-Status: Backport [<a href="https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd" rel="noreferrer" target="_blank">https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd</a>]<br>
+<br>
+Signed-off-by: Adam Williamson &lt;<a href="mailto:awilliam@redhat.com" target="_blank">awilliam@redhat.com</a>&gt;<br>
+Signed-off-by: Patrick Uiterwijk &lt;<a href="mailto:puiterwijk@redhat.com" target="_blank">puiterwijk@redhat.com</a>&gt;<br>
+---<br>
+ src/basic/parse-util.c       | 24 ++++++++++++++++++++++<br>
+ src/basic/parse-util.h       |  2 ++<br>
+ src/test/test-parse-util.c   | 39 ++++++++++++++++++++++++++++++++++++<br>
+ src/udev/udev-builtin-hwdb.c | 13 ++++++------<br>
+ 4 files changed, 71 insertions(+), 7 deletions(-)<br>
+<br>
+diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c<br>
+index 97533721d..ff3fc298a 100644<br>
+--- a/src/basic/parse-util.c<br>
++++ b/src/basic/parse-util.c<br>
+@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {<br>
+         return 0;<br>
+ }<br>
+ <br>
++int safe_atoux16(const char *s, uint16_t *ret) {<br>
++        char *x = NULL;<br>
++        unsigned long l;<br>
++<br>
++        assert(s);<br>
++        assert(ret);<br>
++<br>
++        s += strspn(s, WHITESPACE);<br>
++<br>
++        errno = 0;<br>
++        l = strtoul(s, &amp;x, 16);<br>
++        if (errno &gt; 0)<br>
++                return -errno;<br>
++        if (!x || x == s || *x != 0)<br>
++                return -EINVAL;<br>
++        if (s[0] == &#39;-&#39;)<br>
++                return -ERANGE;<br>
++        if ((unsigned long) (uint16_t) l != l)<br>
++                return -ERANGE;<br>
++<br>
++        *ret = (uint16_t) l;<br>
++        return 0;<br>
++}<br>
++<br>
+ int safe_atod(const char *s, double *ret_d) {<br>
+         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;<br>
+         char *x = NULL;<br>
+diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h<br>
+index 1eda1d7f9..727422056 100644<br>
+--- a/src/basic/parse-util.h<br>
++++ b/src/basic/parse-util.h<br>
+@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);<br>
+ int safe_atou16(const char *s, uint16_t *ret);<br>
+ int safe_atoi16(const char *s, int16_t *ret);<br>
+ <br>
++int safe_atoux16(const char *s, uint16_t *ret);<br>
++<br>
+ static inline int safe_atou32(const char *s, uint32_t *ret_u) {<br>
+         assert_cc(sizeof(uint32_t) == sizeof(unsigned));<br>
+         return safe_atou(s, (unsigned*) ret_u);<br>
+diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c<br>
+index 937500213..a99cea5a1 100644<br>
+--- a/src/test/test-parse-util.c<br>
++++ b/src/test/test-parse-util.c<br>
+@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {<br>
+         assert_se(r == -EINVAL);<br>
+ }<br>
+ <br>
++static void test_safe_atoux16(void) {<br>
++        int r;<br>
++        uint16_t l;<br>
++<br>
++        r = safe_atoux16(&quot;1234&quot;, &amp;l);<br>
++        assert_se(r == 0);<br>
++        assert_se(l == 0x1234);<br>
++<br>
++        r = safe_atoux16(&quot;abcd&quot;, &amp;l);<br>
++        assert_se(r == 0);<br>
++        assert_se(l == 0xabcd);<br>
++<br>
++        r = safe_atoux16(&quot;  1234&quot;, &amp;l);<br>
++        assert_se(r == 0);<br>
++        assert_se(l == 0x1234);<br>
++<br>
++        r = safe_atoux16(&quot;12345&quot;, &amp;l);<br>
++        assert_se(r == -ERANGE);<br>
++<br>
++        r = safe_atoux16(&quot;-1&quot;, &amp;l);<br>
++        assert_se(r == -ERANGE);<br>
++<br>
++        r = safe_atoux16(&quot;  -1&quot;, &amp;l);<br>
++        assert_se(r == -ERANGE);<br>
++<br>
++        r = safe_atoux16(&quot;junk&quot;, &amp;l);<br>
++        assert_se(r == -EINVAL);<br>
++<br>
++        r = safe_atoux16(&quot;123x&quot;, &amp;l);<br>
++        assert_se(r == -EINVAL);<br>
++<br>
++        r = safe_atoux16(&quot;12.3&quot;, &amp;l);<br>
++        assert_se(r == -EINVAL);<br>
++<br>
++        r = safe_atoux16(&quot;&quot;, &amp;l);<br>
++        assert_se(r == -EINVAL);<br>
++}<br>
++<br>
+ static void test_safe_atou64(void) {<br>
+         int r;<br>
+         uint64_t l;<br>
+@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {<br>
+         test_safe_atolli();<br>
+         test_safe_atou16();<br>
+         test_safe_atoi16();<br>
++        test_safe_atoux16();<br>
+         test_safe_atou64();<br>
+         test_safe_atoi64();<br>
+         test_safe_atod();<br>
+diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c<br>
+index ca7f7c230..dbfe02429 100644<br>
+--- a/src/udev/udev-builtin-hwdb.c<br>
++++ b/src/udev/udev-builtin-hwdb.c<br>
+@@ -27,6 +27,7 @@<br>
+ <br>
+ #include &quot;alloc-util.h&quot;<br>
+ #include &quot;hwdb-util.h&quot;<br>
++#include &quot;parse-util.h&quot;<br>
+ #include &quot;string-util.h&quot;<br>
+ #include &quot;udev-util.h&quot;<br>
+ #include &quot;udev.h&quot;<br>
+@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev,<br>
+ <br>
+ static const char *modalias_usb(struct udev_device *dev, char *s, size_t size) {<br>
+         const char *v, *p;<br>
+-        int vn, pn;<br>
++        uint16_t vn, pn;<br>
+ <br>
+         v = udev_device_get_sysattr_value(dev, &quot;idVendor&quot;);<br>
+         if (!v)<br>
+@@ -71,12 +72,10 @@ static const char *modalias_usb(struct udev_device *dev, char *s, size_t size) {<br>
+         p = udev_device_get_sysattr_value(dev, &quot;idProduct&quot;);<br>
+         if (!p)<br>
+                 return NULL;<br>
+-        vn = strtol(v, NULL, 16);<br>
+-        if (vn &lt;= 0)<br>
+-                return NULL;<br>
+-        pn = strtol(p, NULL, 16);<br>
+-        if (pn &lt;= 0)<br>
+-                return NULL;<br>
++        if (safe_atoux16(v, &amp;vn) &lt; 0)<br>
++              return NULL;<br>
++        if (safe_atoux16(p, &amp;pn) &lt; 0)<br>
++              return NULL;<br>
+         snprintf(s, size, &quot;usb:v%04Xp%04X*&quot;, vn, pn);<br>
+         return s;<br>
+ }<br>
+-- <br>
+2.17.0<br>
+<br>
diff --git a/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a> b/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
index b7c2113255..c4743a6b9d 100644<br>
--- a/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
+++ b/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
@@ -52,6 +52,7 @@ SRC_URI += &quot;file://touchscreen.rules \<br>
            file://0032-memfd.patch \<br>
            file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \<br>
            file://libmount.patch \<br>
+           file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \<br>
            &quot;<br>
 SRC_URI_append_qemuall = &quot; file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch&quot;<br>
<br>
-- <br>
2.17.0<br>
<br>
-- <br>
_______________________________________________<br>
Openembedded-core mailing list<br>
<a href="mailto:Openembedded-core@lists.openembedded.org" target="_blank">Openembedded-core@lists.openembedded.org</a><br>
<a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/mailman/listinfo/openembedded-core</a><br>
</blockquote></div>
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Khem Raj May 31, 2018, 4:17 p.m. UTC | #2
On Thu, May 31, 2018 at 9:05 AM, Martin Jansa <martin.jansa@gmail.com> wrote:
> Unlike the previous version you had in your RFT branch (which added

> -Wno-error=format-truncation) this doesn't seem to be complete fix.

>

> In qemux86 build which already includes this change I'm seeing:

> ../git/src/basic/time-util.c: In function 'format_timespan':

> ../git/src/basic/time-util.c:508:46: error: '%0*llu' directive output

> between 1 and 2147483647 bytes may cause result to exceed 'INT_MAX'

> [-Werror=format-truncation=]

>

> "%s"USEC_FMT".%0*"PRI_USEC"%s",

>                                               ^~~~

> ../git/src/basic/time-util.c:508:60: note: format string is defined here

>

> "%s"USEC_FMT".%0*"PRI_USEC"%s",

> ../git/src/basic/time-util.c:508:46: note: directive argument in the range

> [0, 18446744073709551614]

>

> "%s"USEC_FMT".%0*"PRI_USEC"%s",

>                                               ^~~~

>

> And this part doesn't seem to be fixed upstream yet.

>


Its possible, that default config I build is not using this code. Do
you enable/disable some specific packageconfig and what arch are you
targetting

> Cheers,

>

> On Mon, May 28, 2018 at 5:58 PM Khem Raj <raj.khem@gmail.com> wrote:

>>

>> Signed-off-by: Khem Raj <raj.khem@gmail.com>

>> ---

>>  ...ange-the-default-device-timeout-to-2.patch |   9 +-

>>  ...ation-compile-failure-by-typecasting.patch | 173 ++++++++++++++++++

>>  meta/recipes-core/systemd/systemd_237.bb      |   1 +

>>  3 files changed, 177 insertions(+), 6 deletions(-)

>>  create mode 100644

>> meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>>

>> diff --git

>> a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>> b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>> index b7b1ea0886..98c83620ff 100644

>> ---

>> a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>> +++

>> b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>> @@ -1,4 +1,4 @@

>> -From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17 00:00:00 2001

>> +From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17 00:00:00 2001

>>  From: Khem Raj <raj.khem@gmail.com>

>>  Date: Mon, 14 Dec 2015 04:09:19 +0000

>>  Subject: [PATCH] core/device.c: Change the default device timeout to 240

>> sec.

>> @@ -16,10 +16,10 @@ Signed-off-by: Khem Raj <raj.khem@gmail.com>

>>   1 file changed, 1 insertion(+), 1 deletion(-)

>>

>>  diff --git a/src/core/device.c b/src/core/device.c

>> -index 77601c552..98bf49ba2 100644

>> +index a43664d3b..4b16a8aec 100644

>>  --- a/src/core/device.c

>>  +++ b/src/core/device.c

>> -@@ -112,7 +112,7 @@ static void device_init(Unit *u) {

>> +@@ -113,7 +113,7 @@ static void device_init(Unit *u) {

>>            * indefinitely for plugged in devices, something which cannot

>>            * happen for the other units since their operations time out

>>            * anyway. */

>> @@ -28,6 +28,3 @@ index 77601c552..98bf49ba2 100644

>>

>>           u->ignore_on_isolate = true;

>>   }

>> ---

>> -2.16.1

>> -

>> diff --git

>> a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>> b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>> new file mode 100644

>> index 0000000000..e56061f41b

>> --- /dev/null

>> +++

>> b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>> @@ -0,0 +1,173 @@

>> +From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17 00:00:00 2001

>> +From: Patrick Uiterwijk <patrick@puiterwijk.org>

>> +Date: Thu, 22 Feb 2018 19:41:30 +0100

>> +Subject: [PATCH] Fix format-truncation compile failure by typecasting USB

>> IDs

>> + (#8250)

>> +

>> +This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit

>> int, and

>> +uses that for parsing USB device and vendor IDs.

>> +

>> +This fixes a compile error with gcc-8 because while we know that USB IDs

>> are 2 bytes,

>> +the compiler does not know that.

>> +

>> +../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may

>> be

>> +truncated writing between 4 and 8 bytes into a region of size between 2

>> and 6

>> +[-Werror=format-truncation=]

>> +

>> +Upstream-Status: Backport

>> [https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd]

>> +

>> +Signed-off-by: Adam Williamson <awilliam@redhat.com>

>> +Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>

>> +---

>> + src/basic/parse-util.c       | 24 ++++++++++++++++++++++

>> + src/basic/parse-util.h       |  2 ++

>> + src/test/test-parse-util.c   | 39 ++++++++++++++++++++++++++++++++++++

>> + src/udev/udev-builtin-hwdb.c | 13 ++++++------

>> + 4 files changed, 71 insertions(+), 7 deletions(-)

>> +

>> +diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c

>> +index 97533721d..ff3fc298a 100644

>> +--- a/src/basic/parse-util.c

>> ++++ b/src/basic/parse-util.c

>> +@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {

>> +         return 0;

>> + }

>> +

>> ++int safe_atoux16(const char *s, uint16_t *ret) {

>> ++        char *x = NULL;

>> ++        unsigned long l;

>> ++

>> ++        assert(s);

>> ++        assert(ret);

>> ++

>> ++        s += strspn(s, WHITESPACE);

>> ++

>> ++        errno = 0;

>> ++        l = strtoul(s, &x, 16);

>> ++        if (errno > 0)

>> ++                return -errno;

>> ++        if (!x || x == s || *x != 0)

>> ++                return -EINVAL;

>> ++        if (s[0] == '-')

>> ++                return -ERANGE;

>> ++        if ((unsigned long) (uint16_t) l != l)

>> ++                return -ERANGE;

>> ++

>> ++        *ret = (uint16_t) l;

>> ++        return 0;

>> ++}

>> ++

>> + int safe_atod(const char *s, double *ret_d) {

>> +         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;

>> +         char *x = NULL;

>> +diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h

>> +index 1eda1d7f9..727422056 100644

>> +--- a/src/basic/parse-util.h

>> ++++ b/src/basic/parse-util.h

>> +@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);

>> + int safe_atou16(const char *s, uint16_t *ret);

>> + int safe_atoi16(const char *s, int16_t *ret);

>> +

>> ++int safe_atoux16(const char *s, uint16_t *ret);

>> ++

>> + static inline int safe_atou32(const char *s, uint32_t *ret_u) {

>> +         assert_cc(sizeof(uint32_t) == sizeof(unsigned));

>> +         return safe_atou(s, (unsigned*) ret_u);

>> +diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c

>> +index 937500213..a99cea5a1 100644

>> +--- a/src/test/test-parse-util.c

>> ++++ b/src/test/test-parse-util.c

>> +@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {

>> +         assert_se(r == -EINVAL);

>> + }

>> +

>> ++static void test_safe_atoux16(void) {

>> ++        int r;

>> ++        uint16_t l;

>> ++

>> ++        r = safe_atoux16("1234", &l);

>> ++        assert_se(r == 0);

>> ++        assert_se(l == 0x1234);

>> ++

>> ++        r = safe_atoux16("abcd", &l);

>> ++        assert_se(r == 0);

>> ++        assert_se(l == 0xabcd);

>> ++

>> ++        r = safe_atoux16("  1234", &l);

>> ++        assert_se(r == 0);

>> ++        assert_se(l == 0x1234);

>> ++

>> ++        r = safe_atoux16("12345", &l);

>> ++        assert_se(r == -ERANGE);

>> ++

>> ++        r = safe_atoux16("-1", &l);

>> ++        assert_se(r == -ERANGE);

>> ++

>> ++        r = safe_atoux16("  -1", &l);

>> ++        assert_se(r == -ERANGE);

>> ++

>> ++        r = safe_atoux16("junk", &l);

>> ++        assert_se(r == -EINVAL);

>> ++

>> ++        r = safe_atoux16("123x", &l);

>> ++        assert_se(r == -EINVAL);

>> ++

>> ++        r = safe_atoux16("12.3", &l);

>> ++        assert_se(r == -EINVAL);

>> ++

>> ++        r = safe_atoux16("", &l);

>> ++        assert_se(r == -EINVAL);

>> ++}

>> ++

>> + static void test_safe_atou64(void) {

>> +         int r;

>> +         uint64_t l;

>> +@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {

>> +         test_safe_atolli();

>> +         test_safe_atou16();

>> +         test_safe_atoi16();

>> ++        test_safe_atoux16();

>> +         test_safe_atou64();

>> +         test_safe_atoi64();

>> +         test_safe_atod();

>> +diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c

>> +index ca7f7c230..dbfe02429 100644

>> +--- a/src/udev/udev-builtin-hwdb.c

>> ++++ b/src/udev/udev-builtin-hwdb.c

>> +@@ -27,6 +27,7 @@

>> +

>> + #include "alloc-util.h"

>> + #include "hwdb-util.h"

>> ++#include "parse-util.h"

>> + #include "string-util.h"

>> + #include "udev-util.h"

>> + #include "udev.h"

>> +@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev,

>> +

>> + static const char *modalias_usb(struct udev_device *dev, char *s, size_t

>> size) {

>> +         const char *v, *p;

>> +-        int vn, pn;

>> ++        uint16_t vn, pn;

>> +

>> +         v = udev_device_get_sysattr_value(dev, "idVendor");

>> +         if (!v)

>> +@@ -71,12 +72,10 @@ static const char *modalias_usb(struct udev_device

>> *dev, char *s, size_t size) {

>> +         p = udev_device_get_sysattr_value(dev, "idProduct");

>> +         if (!p)

>> +                 return NULL;

>> +-        vn = strtol(v, NULL, 16);

>> +-        if (vn <= 0)

>> +-                return NULL;

>> +-        pn = strtol(p, NULL, 16);

>> +-        if (pn <= 0)

>> +-                return NULL;

>> ++        if (safe_atoux16(v, &vn) < 0)

>> ++              return NULL;

>> ++        if (safe_atoux16(p, &pn) < 0)

>> ++              return NULL;

>> +         snprintf(s, size, "usb:v%04Xp%04X*", vn, pn);

>> +         return s;

>> + }

>> +--

>> +2.17.0

>> +

>> diff --git a/meta/recipes-core/systemd/systemd_237.bb

>> b/meta/recipes-core/systemd/systemd_237.bb

>> index b7c2113255..c4743a6b9d 100644

>> --- a/meta/recipes-core/systemd/systemd_237.bb

>> +++ b/meta/recipes-core/systemd/systemd_237.bb

>> @@ -52,6 +52,7 @@ SRC_URI += "file://touchscreen.rules \

>>             file://0032-memfd.patch \

>>

>> file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \

>>             file://libmount.patch \

>> +

>> file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \

>>             "

>>  SRC_URI_append_qemuall = "

>> file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"

>>

>> --

>> 2.17.0

>>

>> --

>> _______________________________________________

>> Openembedded-core mailing list

>> Openembedded-core@lists.openembedded.org

>> http://lists.openembedded.org/mailman/listinfo/openembedded-core

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Martin Jansa June 1, 2018, 2:01 p.m. UTC | #3
No change in PACKAGECONFIG, just default nodistro qemux86 with added
systemd and debug build:
DISTRO_FEATURES_append = " systemd"
DEBUG_BUILD = "1"


On Thu, May 31, 2018 at 6:17 PM Khem Raj <raj.khem@gmail.com> wrote:

> On Thu, May 31, 2018 at 9:05 AM, Martin Jansa <martin.jansa@gmail.com>

> wrote:

> > Unlike the previous version you had in your RFT branch (which added

> > -Wno-error=format-truncation) this doesn't seem to be complete fix.

> >

> > In qemux86 build which already includes this change I'm seeing:

> > ../git/src/basic/time-util.c: In function 'format_timespan':

> > ../git/src/basic/time-util.c:508:46: error: '%0*llu' directive output

> > between 1 and 2147483647 bytes may cause result to exceed 'INT_MAX'

> > [-Werror=format-truncation=]

> >

> > "%s"USEC_FMT".%0*"PRI_USEC"%s",

> >                                               ^~~~

> > ../git/src/basic/time-util.c:508:60: note: format string is defined here

> >

> > "%s"USEC_FMT".%0*"PRI_USEC"%s",

> > ../git/src/basic/time-util.c:508:46: note: directive argument in the

> range

> > [0, 18446744073709551614]

> >

> > "%s"USEC_FMT".%0*"PRI_USEC"%s",

> >                                               ^~~~

> >

> > And this part doesn't seem to be fixed upstream yet.

> >

>

> Its possible, that default config I build is not using this code. Do

> you enable/disable some specific packageconfig and what arch are you

> targetting

>

> > Cheers,

> >

> > On Mon, May 28, 2018 at 5:58 PM Khem Raj <raj.khem@gmail.com> wrote:

> >>

> >> Signed-off-by: Khem Raj <raj.khem@gmail.com>

> >> ---

> >>  ...ange-the-default-device-timeout-to-2.patch |   9 +-

> >>  ...ation-compile-failure-by-typecasting.patch | 173 ++++++++++++++++++

> >>  meta/recipes-core/systemd/systemd_237.bb      |   1 +

> >>  3 files changed, 177 insertions(+), 6 deletions(-)

> >>  create mode 100644

> >>

> meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

> >>

> >> diff --git

> >>

> a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

> >>

> b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

> >> index b7b1ea0886..98c83620ff 100644

> >> ---

> >>

> a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

> >> +++

> >>

> b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

> >> @@ -1,4 +1,4 @@

> >> -From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17 00:00:00 2001

> >> +From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17 00:00:00 2001

> >>  From: Khem Raj <raj.khem@gmail.com>

> >>  Date: Mon, 14 Dec 2015 04:09:19 +0000

> >>  Subject: [PATCH] core/device.c: Change the default device timeout to

> 240

> >> sec.

> >> @@ -16,10 +16,10 @@ Signed-off-by: Khem Raj <raj.khem@gmail.com>

> >>   1 file changed, 1 insertion(+), 1 deletion(-)

> >>

> >>  diff --git a/src/core/device.c b/src/core/device.c

> >> -index 77601c552..98bf49ba2 100644

> >> +index a43664d3b..4b16a8aec 100644

> >>  --- a/src/core/device.c

> >>  +++ b/src/core/device.c

> >> -@@ -112,7 +112,7 @@ static void device_init(Unit *u) {

> >> +@@ -113,7 +113,7 @@ static void device_init(Unit *u) {

> >>            * indefinitely for plugged in devices, something which cannot

> >>            * happen for the other units since their operations time out

> >>            * anyway. */

> >> @@ -28,6 +28,3 @@ index 77601c552..98bf49ba2 100644

> >>

> >>           u->ignore_on_isolate = true;

> >>   }

> >> ---

> >> -2.16.1

> >> -

> >> diff --git

> >>

> a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

> >>

> b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

> >> new file mode 100644

> >> index 0000000000..e56061f41b

> >> --- /dev/null

> >> +++

> >>

> b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

> >> @@ -0,0 +1,173 @@

> >> +From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17 00:00:00 2001

> >> +From: Patrick Uiterwijk <patrick@puiterwijk.org>

> >> +Date: Thu, 22 Feb 2018 19:41:30 +0100

> >> +Subject: [PATCH] Fix format-truncation compile failure by typecasting

> USB

> >> IDs

> >> + (#8250)

> >> +

> >> +This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit

> >> int, and

> >> +uses that for parsing USB device and vendor IDs.

> >> +

> >> +This fixes a compile error with gcc-8 because while we know that USB

> IDs

> >> are 2 bytes,

> >> +the compiler does not know that.

> >> +

> >> +../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output

> may

> >> be

> >> +truncated writing between 4 and 8 bytes into a region of size between 2

> >> and 6

> >> +[-Werror=format-truncation=]

> >> +

> >> +Upstream-Status: Backport

> >> [

> https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd

> ]

> >> +

> >> +Signed-off-by: Adam Williamson <awilliam@redhat.com>

> >> +Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>

> >> +---

> >> + src/basic/parse-util.c       | 24 ++++++++++++++++++++++

> >> + src/basic/parse-util.h       |  2 ++

> >> + src/test/test-parse-util.c   | 39 ++++++++++++++++++++++++++++++++++++

> >> + src/udev/udev-builtin-hwdb.c | 13 ++++++------

> >> + 4 files changed, 71 insertions(+), 7 deletions(-)

> >> +

> >> +diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c

> >> +index 97533721d..ff3fc298a 100644

> >> +--- a/src/basic/parse-util.c

> >> ++++ b/src/basic/parse-util.c

> >> +@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {

> >> +         return 0;

> >> + }

> >> +

> >> ++int safe_atoux16(const char *s, uint16_t *ret) {

> >> ++        char *x = NULL;

> >> ++        unsigned long l;

> >> ++

> >> ++        assert(s);

> >> ++        assert(ret);

> >> ++

> >> ++        s += strspn(s, WHITESPACE);

> >> ++

> >> ++        errno = 0;

> >> ++        l = strtoul(s, &x, 16);

> >> ++        if (errno > 0)

> >> ++                return -errno;

> >> ++        if (!x || x == s || *x != 0)

> >> ++                return -EINVAL;

> >> ++        if (s[0] == '-')

> >> ++                return -ERANGE;

> >> ++        if ((unsigned long) (uint16_t) l != l)

> >> ++                return -ERANGE;

> >> ++

> >> ++        *ret = (uint16_t) l;

> >> ++        return 0;

> >> ++}

> >> ++

> >> + int safe_atod(const char *s, double *ret_d) {

> >> +         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;

> >> +         char *x = NULL;

> >> +diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h

> >> +index 1eda1d7f9..727422056 100644

> >> +--- a/src/basic/parse-util.h

> >> ++++ b/src/basic/parse-util.h

> >> +@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);

> >> + int safe_atou16(const char *s, uint16_t *ret);

> >> + int safe_atoi16(const char *s, int16_t *ret);

> >> +

> >> ++int safe_atoux16(const char *s, uint16_t *ret);

> >> ++

> >> + static inline int safe_atou32(const char *s, uint32_t *ret_u) {

> >> +         assert_cc(sizeof(uint32_t) == sizeof(unsigned));

> >> +         return safe_atou(s, (unsigned*) ret_u);

> >> +diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c

> >> +index 937500213..a99cea5a1 100644

> >> +--- a/src/test/test-parse-util.c

> >> ++++ b/src/test/test-parse-util.c

> >> +@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {

> >> +         assert_se(r == -EINVAL);

> >> + }

> >> +

> >> ++static void test_safe_atoux16(void) {

> >> ++        int r;

> >> ++        uint16_t l;

> >> ++

> >> ++        r = safe_atoux16("1234", &l);

> >> ++        assert_se(r == 0);

> >> ++        assert_se(l == 0x1234);

> >> ++

> >> ++        r = safe_atoux16("abcd", &l);

> >> ++        assert_se(r == 0);

> >> ++        assert_se(l == 0xabcd);

> >> ++

> >> ++        r = safe_atoux16("  1234", &l);

> >> ++        assert_se(r == 0);

> >> ++        assert_se(l == 0x1234);

> >> ++

> >> ++        r = safe_atoux16("12345", &l);

> >> ++        assert_se(r == -ERANGE);

> >> ++

> >> ++        r = safe_atoux16("-1", &l);

> >> ++        assert_se(r == -ERANGE);

> >> ++

> >> ++        r = safe_atoux16("  -1", &l);

> >> ++        assert_se(r == -ERANGE);

> >> ++

> >> ++        r = safe_atoux16("junk", &l);

> >> ++        assert_se(r == -EINVAL);

> >> ++

> >> ++        r = safe_atoux16("123x", &l);

> >> ++        assert_se(r == -EINVAL);

> >> ++

> >> ++        r = safe_atoux16("12.3", &l);

> >> ++        assert_se(r == -EINVAL);

> >> ++

> >> ++        r = safe_atoux16("", &l);

> >> ++        assert_se(r == -EINVAL);

> >> ++}

> >> ++

> >> + static void test_safe_atou64(void) {

> >> +         int r;

> >> +         uint64_t l;

> >> +@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {

> >> +         test_safe_atolli();

> >> +         test_safe_atou16();

> >> +         test_safe_atoi16();

> >> ++        test_safe_atoux16();

> >> +         test_safe_atou64();

> >> +         test_safe_atoi64();

> >> +         test_safe_atod();

> >> +diff --git a/src/udev/udev-builtin-hwdb.c

> b/src/udev/udev-builtin-hwdb.c

> >> +index ca7f7c230..dbfe02429 100644

> >> +--- a/src/udev/udev-builtin-hwdb.c

> >> ++++ b/src/udev/udev-builtin-hwdb.c

> >> +@@ -27,6 +27,7 @@

> >> +

> >> + #include "alloc-util.h"

> >> + #include "hwdb-util.h"

> >> ++#include "parse-util.h"

> >> + #include "string-util.h"

> >> + #include "udev-util.h"

> >> + #include "udev.h"

> >> +@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev,

> >> +

> >> + static const char *modalias_usb(struct udev_device *dev, char *s,

> size_t

> >> size) {

> >> +         const char *v, *p;

> >> +-        int vn, pn;

> >> ++        uint16_t vn, pn;

> >> +

> >> +         v = udev_device_get_sysattr_value(dev, "idVendor");

> >> +         if (!v)

> >> +@@ -71,12 +72,10 @@ static const char *modalias_usb(struct udev_device

> >> *dev, char *s, size_t size) {

> >> +         p = udev_device_get_sysattr_value(dev, "idProduct");

> >> +         if (!p)

> >> +                 return NULL;

> >> +-        vn = strtol(v, NULL, 16);

> >> +-        if (vn <= 0)

> >> +-                return NULL;

> >> +-        pn = strtol(p, NULL, 16);

> >> +-        if (pn <= 0)

> >> +-                return NULL;

> >> ++        if (safe_atoux16(v, &vn) < 0)

> >> ++              return NULL;

> >> ++        if (safe_atoux16(p, &pn) < 0)

> >> ++              return NULL;

> >> +         snprintf(s, size, "usb:v%04Xp%04X*", vn, pn);

> >> +         return s;

> >> + }

> >> +--

> >> +2.17.0

> >> +

> >> diff --git a/meta/recipes-core/systemd/systemd_237.bb

> >> b/meta/recipes-core/systemd/systemd_237.bb

> >> index b7c2113255..c4743a6b9d 100644

> >> --- a/meta/recipes-core/systemd/systemd_237.bb

> >> +++ b/meta/recipes-core/systemd/systemd_237.bb

> >> @@ -52,6 +52,7 @@ SRC_URI += "file://touchscreen.rules \

> >>             file://0032-memfd.patch \

> >>

> >> file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \

> >>             file://libmount.patch \

> >> +

> >> file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \

> >>             "

> >>  SRC_URI_append_qemuall = "

> >> file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"

> >>

> >> --

> >> 2.17.0

> >>

> >> --

> >> _______________________________________________

> >> Openembedded-core mailing list

> >> Openembedded-core@lists.openembedded.org

> >> http://lists.openembedded.org/mailman/listinfo/openembedded-core

>
<div dir="ltr"><div>No change in PACKAGECONFIG, just default nodistro qemux86 with added systemd and debug build:</div><div><div>DISTRO_FEATURES_append = &quot; systemd&quot;</div><div>DEBUG_BUILD = &quot;1&quot;</div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 31, 2018 at 6:17 PM Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, May 31, 2018 at 9:05 AM, Martin Jansa &lt;<a href="mailto:martin.jansa@gmail.com" target="_blank">martin.jansa@gmail.com</a>&gt; wrote:<br>
&gt; Unlike the previous version you had in your RFT branch (which added<br>
&gt; -Wno-error=format-truncation) this doesn&#39;t seem to be complete fix.<br>
&gt;<br>
&gt; In qemux86 build which already includes this change I&#39;m seeing:<br>
&gt; ../git/src/basic/time-util.c: In function &#39;format_timespan&#39;:<br>
&gt; ../git/src/basic/time-util.c:508:46: error: &#39;%0*llu&#39; directive output<br>
&gt; between 1 and 2147483647 bytes may cause result to exceed &#39;INT_MAX&#39;<br>
&gt; [-Werror=format-truncation=]<br>
&gt;<br>
&gt; &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,<br>
&gt;                                               ^~~~<br>
&gt; ../git/src/basic/time-util.c:508:60: note: format string is defined here<br>
&gt;<br>
&gt; &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,<br>
&gt; ../git/src/basic/time-util.c:508:46: note: directive argument in the range<br>
&gt; [0, 18446744073709551614]<br>
&gt;<br>
&gt; &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,<br>
&gt;                                               ^~~~<br>
&gt;<br>
&gt; And this part doesn&#39;t seem to be fixed upstream yet.<br>
&gt;<br>
<br>
Its possible, that default config I build is not using this code. Do<br>
you enable/disable some specific packageconfig and what arch are you<br>
targetting<br>
<br>
&gt; Cheers,<br>
&gt;<br>
&gt; On Mon, May 28, 2018 at 5:58 PM Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Signed-off-by: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
&gt;&gt; ---<br>
&gt;&gt;  ...ange-the-default-device-timeout-to-2.patch |   9 +-<br>
&gt;&gt;  ...ation-compile-failure-by-typecasting.patch | 173 ++++++++++++++++++<br>
&gt;&gt;  meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a>      |   1 +<br>
&gt;&gt;  3 files changed, 177 insertions(+), 6 deletions(-)<br>
&gt;&gt;  create mode 100644<br>
&gt;&gt; meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
&gt;&gt;<br>
&gt;&gt; diff --git<br>
&gt;&gt; a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
&gt;&gt; b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
&gt;&gt; index b7b1ea0886..98c83620ff 100644<br>
&gt;&gt; ---<br>
&gt;&gt; a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
&gt;&gt; +++<br>
&gt;&gt; b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
&gt;&gt; @@ -1,4 +1,4 @@<br>
&gt;&gt; -From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17 00:00:00 2001<br>
&gt;&gt; +From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17 00:00:00 2001<br>
&gt;&gt;  From: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
&gt;&gt;  Date: Mon, 14 Dec 2015 04:09:19 +0000<br>
&gt;&gt;  Subject: [PATCH] core/device.c: Change the default device timeout to 240<br>
&gt;&gt; sec.<br>
&gt;&gt; @@ -16,10 +16,10 @@ Signed-off-by: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
&gt;&gt;   1 file changed, 1 insertion(+), 1 deletion(-)<br>
&gt;&gt;<br>
&gt;&gt;  diff --git a/src/core/device.c b/src/core/device.c<br>
&gt;&gt; -index 77601c552..98bf49ba2 100644<br>
&gt;&gt; +index a43664d3b..4b16a8aec 100644<br>
&gt;&gt;  --- a/src/core/device.c<br>
&gt;&gt;  +++ b/src/core/device.c<br>
&gt;&gt; -@@ -112,7 +112,7 @@ static void device_init(Unit *u) {<br>
&gt;&gt; +@@ -113,7 +113,7 @@ static void device_init(Unit *u) {<br>
&gt;&gt;            * indefinitely for plugged in devices, something which cannot<br>
&gt;&gt;            * happen for the other units since their operations time out<br>
&gt;&gt;            * anyway. */<br>
&gt;&gt; @@ -28,6 +28,3 @@ index 77601c552..98bf49ba2 100644<br>
&gt;&gt;<br>
&gt;&gt;           u-&gt;ignore_on_isolate = true;<br>
&gt;&gt;   }<br>
&gt;&gt; ---<br>
&gt;&gt; -2.16.1<br>
&gt;&gt; -<br>
&gt;&gt; diff --git<br>
&gt;&gt; a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
&gt;&gt; b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
&gt;&gt; new file mode 100644<br>
&gt;&gt; index 0000000000..e56061f41b<br>
&gt;&gt; --- /dev/null<br>
&gt;&gt; +++<br>
&gt;&gt; b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
&gt;&gt; @@ -0,0 +1,173 @@<br>
&gt;&gt; +From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17 00:00:00 2001<br>
&gt;&gt; +From: Patrick Uiterwijk &lt;<a href="mailto:patrick@puiterwijk.org" target="_blank">patrick@puiterwijk.org</a>&gt;<br>
&gt;&gt; +Date: Thu, 22 Feb 2018 19:41:30 +0100<br>
&gt;&gt; +Subject: [PATCH] Fix format-truncation compile failure by typecasting USB<br>
&gt;&gt; IDs<br>
&gt;&gt; + (#8250)<br>
&gt;&gt; +<br>
&gt;&gt; +This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit<br>
&gt;&gt; int, and<br>
&gt;&gt; +uses that for parsing USB device and vendor IDs.<br>
&gt;&gt; +<br>
&gt;&gt; +This fixes a compile error with gcc-8 because while we know that USB IDs<br>
&gt;&gt; are 2 bytes,<br>
&gt;&gt; +the compiler does not know that.<br>
&gt;&gt; +<br>
&gt;&gt; +../src/udev/udev-builtin-hwdb.c:80:38: error: &#39;%04X&#39; directive output may<br>
&gt;&gt; be<br>
&gt;&gt; +truncated writing between 4 and 8 bytes into a region of size between 2<br>
&gt;&gt; and 6<br>
&gt;&gt; +[-Werror=format-truncation=]<br>
&gt;&gt; +<br>
&gt;&gt; +Upstream-Status: Backport<br>
&gt;&gt; [<a href="https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd" rel="noreferrer" target="_blank">https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd</a>]<br>
&gt;&gt; +<br>
&gt;&gt; +Signed-off-by: Adam Williamson &lt;<a href="mailto:awilliam@redhat.com" target="_blank">awilliam@redhat.com</a>&gt;<br>
&gt;&gt; +Signed-off-by: Patrick Uiterwijk &lt;<a href="mailto:puiterwijk@redhat.com" target="_blank">puiterwijk@redhat.com</a>&gt;<br>
&gt;&gt; +---<br>
&gt;&gt; + src/basic/parse-util.c       | 24 ++++++++++++++++++++++<br>
&gt;&gt; + src/basic/parse-util.h       |  2 ++<br>
&gt;&gt; + src/test/test-parse-util.c   | 39 ++++++++++++++++++++++++++++++++++++<br>
&gt;&gt; + src/udev/udev-builtin-hwdb.c | 13 ++++++------<br>
&gt;&gt; + 4 files changed, 71 insertions(+), 7 deletions(-)<br>
&gt;&gt; +<br>
&gt;&gt; +diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c<br>
&gt;&gt; +index 97533721d..ff3fc298a 100644<br>
&gt;&gt; +--- a/src/basic/parse-util.c<br>
&gt;&gt; ++++ b/src/basic/parse-util.c<br>
&gt;&gt; +@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {<br>
&gt;&gt; +         return 0;<br>
&gt;&gt; + }<br>
&gt;&gt; +<br>
&gt;&gt; ++int safe_atoux16(const char *s, uint16_t *ret) {<br>
&gt;&gt; ++        char *x = NULL;<br>
&gt;&gt; ++        unsigned long l;<br>
&gt;&gt; ++<br>
&gt;&gt; ++        assert(s);<br>
&gt;&gt; ++        assert(ret);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        s += strspn(s, WHITESPACE);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        errno = 0;<br>
&gt;&gt; ++        l = strtoul(s, &amp;x, 16);<br>
&gt;&gt; ++        if (errno &gt; 0)<br>
&gt;&gt; ++                return -errno;<br>
&gt;&gt; ++        if (!x || x == s || *x != 0)<br>
&gt;&gt; ++                return -EINVAL;<br>
&gt;&gt; ++        if (s[0] == &#39;-&#39;)<br>
&gt;&gt; ++                return -ERANGE;<br>
&gt;&gt; ++        if ((unsigned long) (uint16_t) l != l)<br>
&gt;&gt; ++                return -ERANGE;<br>
&gt;&gt; ++<br>
&gt;&gt; ++        *ret = (uint16_t) l;<br>
&gt;&gt; ++        return 0;<br>
&gt;&gt; ++}<br>
&gt;&gt; ++<br>
&gt;&gt; + int safe_atod(const char *s, double *ret_d) {<br>
&gt;&gt; +         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;<br>
&gt;&gt; +         char *x = NULL;<br>
&gt;&gt; +diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h<br>
&gt;&gt; +index 1eda1d7f9..727422056 100644<br>
&gt;&gt; +--- a/src/basic/parse-util.h<br>
&gt;&gt; ++++ b/src/basic/parse-util.h<br>
&gt;&gt; +@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);<br>
&gt;&gt; + int safe_atou16(const char *s, uint16_t *ret);<br>
&gt;&gt; + int safe_atoi16(const char *s, int16_t *ret);<br>
&gt;&gt; +<br>
&gt;&gt; ++int safe_atoux16(const char *s, uint16_t *ret);<br>
&gt;&gt; ++<br>
&gt;&gt; + static inline int safe_atou32(const char *s, uint32_t *ret_u) {<br>
&gt;&gt; +         assert_cc(sizeof(uint32_t) == sizeof(unsigned));<br>
&gt;&gt; +         return safe_atou(s, (unsigned*) ret_u);<br>
&gt;&gt; +diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c<br>
&gt;&gt; +index 937500213..a99cea5a1 100644<br>
&gt;&gt; +--- a/src/test/test-parse-util.c<br>
&gt;&gt; ++++ b/src/test/test-parse-util.c<br>
&gt;&gt; +@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {<br>
&gt;&gt; +         assert_se(r == -EINVAL);<br>
&gt;&gt; + }<br>
&gt;&gt; +<br>
&gt;&gt; ++static void test_safe_atoux16(void) {<br>
&gt;&gt; ++        int r;<br>
&gt;&gt; ++        uint16_t l;<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;1234&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == 0);<br>
&gt;&gt; ++        assert_se(l == 0x1234);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;abcd&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == 0);<br>
&gt;&gt; ++        assert_se(l == 0xabcd);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;  1234&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == 0);<br>
&gt;&gt; ++        assert_se(l == 0x1234);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;12345&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -ERANGE);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;-1&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -ERANGE);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;  -1&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -ERANGE);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;junk&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -EINVAL);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;123x&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -EINVAL);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;12.3&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -EINVAL);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -EINVAL);<br>
&gt;&gt; ++}<br>
&gt;&gt; ++<br>
&gt;&gt; + static void test_safe_atou64(void) {<br>
&gt;&gt; +         int r;<br>
&gt;&gt; +         uint64_t l;<br>
&gt;&gt; +@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {<br>
&gt;&gt; +         test_safe_atolli();<br>
&gt;&gt; +         test_safe_atou16();<br>
&gt;&gt; +         test_safe_atoi16();<br>
&gt;&gt; ++        test_safe_atoux16();<br>
&gt;&gt; +         test_safe_atou64();<br>
&gt;&gt; +         test_safe_atoi64();<br>
&gt;&gt; +         test_safe_atod();<br>
&gt;&gt; +diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c<br>
&gt;&gt; +index ca7f7c230..dbfe02429 100644<br>
&gt;&gt; +--- a/src/udev/udev-builtin-hwdb.c<br>
&gt;&gt; ++++ b/src/udev/udev-builtin-hwdb.c<br>
&gt;&gt; +@@ -27,6 +27,7 @@<br>
&gt;&gt; +<br>
&gt;&gt; + #include &quot;alloc-util.h&quot;<br>
&gt;&gt; + #include &quot;hwdb-util.h&quot;<br>
&gt;&gt; ++#include &quot;parse-util.h&quot;<br>
&gt;&gt; + #include &quot;string-util.h&quot;<br>
&gt;&gt; + #include &quot;udev-util.h&quot;<br>
&gt;&gt; + #include &quot;udev.h&quot;<br>
&gt;&gt; +@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev,<br>
&gt;&gt; +<br>
&gt;&gt; + static const char *modalias_usb(struct udev_device *dev, char *s, size_t<br>
&gt;&gt; size) {<br>
&gt;&gt; +         const char *v, *p;<br>
&gt;&gt; +-        int vn, pn;<br>
&gt;&gt; ++        uint16_t vn, pn;<br>
&gt;&gt; +<br>
&gt;&gt; +         v = udev_device_get_sysattr_value(dev, &quot;idVendor&quot;);<br>
&gt;&gt; +         if (!v)<br>
&gt;&gt; +@@ -71,12 +72,10 @@ static const char *modalias_usb(struct udev_device<br>
&gt;&gt; *dev, char *s, size_t size) {<br>
&gt;&gt; +         p = udev_device_get_sysattr_value(dev, &quot;idProduct&quot;);<br>
&gt;&gt; +         if (!p)<br>
&gt;&gt; +                 return NULL;<br>
&gt;&gt; +-        vn = strtol(v, NULL, 16);<br>
&gt;&gt; +-        if (vn &lt;= 0)<br>
&gt;&gt; +-                return NULL;<br>
&gt;&gt; +-        pn = strtol(p, NULL, 16);<br>
&gt;&gt; +-        if (pn &lt;= 0)<br>
&gt;&gt; +-                return NULL;<br>
&gt;&gt; ++        if (safe_atoux16(v, &amp;vn) &lt; 0)<br>
&gt;&gt; ++              return NULL;<br>
&gt;&gt; ++        if (safe_atoux16(p, &amp;pn) &lt; 0)<br>
&gt;&gt; ++              return NULL;<br>
&gt;&gt; +         snprintf(s, size, &quot;usb:v%04Xp%04X*&quot;, vn, pn);<br>
&gt;&gt; +         return s;<br>
&gt;&gt; + }<br>
&gt;&gt; +--<br>
&gt;&gt; +2.17.0<br>
&gt;&gt; +<br>
&gt;&gt; diff --git a/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
&gt;&gt; b/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
&gt;&gt; index b7c2113255..c4743a6b9d 100644<br>
&gt;&gt; --- a/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
&gt;&gt; +++ b/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
&gt;&gt; @@ -52,6 +52,7 @@ SRC_URI += &quot;file://touchscreen.rules \<br>
&gt;&gt;             file://0032-memfd.patch \<br>
&gt;&gt;<br>
&gt;&gt; file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \<br>
&gt;&gt;             file://libmount.patch \<br>
&gt;&gt; +<br>
&gt;&gt; file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \<br>
&gt;&gt;             &quot;<br>
&gt;&gt;  SRC_URI_append_qemuall = &quot;<br>
&gt;&gt; file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch&quot;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; 2.17.0<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Openembedded-core mailing list<br>
&gt;&gt; <a href="mailto:Openembedded-core@lists.openembedded.org" target="_blank">Openembedded-core@lists.openembedded.org</a><br>
&gt;&gt; <a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/mailman/listinfo/openembedded-core</a><br>
</blockquote></div>
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Martin Jansa June 1, 2018, 2:48 p.m. UTC | #4
It fails when -O1 or -Os is being used, builds ok with -O0, -O2, -O3.

Checking a bit more shows that it doesn't fail when -ftree-vrp is used,
probably because this check is removed as the documentation for -ftree-vrp
says:

-ftree-vrp
Perform Value Range Propagation on trees. This is similar to the constant
propagation pass, but instead of values, ranges of values are propagated.
This allows the optimizers to remove unnecessary range checks like array
bound checks and null pointer checks. This is enabled by default at -O2 and
higher. Null pointer check elimination is only done if
-fdelete-null-pointer-checks is enabled.


On Fri, Jun 1, 2018 at 4:01 PM Martin Jansa <martin.jansa@gmail.com> wrote:

> No change in PACKAGECONFIG, just default nodistro qemux86 with added

> systemd and debug build:

> DISTRO_FEATURES_append = " systemd"

> DEBUG_BUILD = "1"

>

>

> On Thu, May 31, 2018 at 6:17 PM Khem Raj <raj.khem@gmail.com> wrote:

>

>> On Thu, May 31, 2018 at 9:05 AM, Martin Jansa <martin.jansa@gmail.com>

>> wrote:

>> > Unlike the previous version you had in your RFT branch (which added

>> > -Wno-error=format-truncation) this doesn't seem to be complete fix.

>> >

>> > In qemux86 build which already includes this change I'm seeing:

>> > ../git/src/basic/time-util.c: In function 'format_timespan':

>> > ../git/src/basic/time-util.c:508:46: error: '%0*llu' directive output

>> > between 1 and 2147483647 bytes may cause result to exceed 'INT_MAX'

>> > [-Werror=format-truncation=]

>> >

>> > "%s"USEC_FMT".%0*"PRI_USEC"%s",

>> >                                               ^~~~

>> > ../git/src/basic/time-util.c:508:60: note: format string is defined here

>> >

>> > "%s"USEC_FMT".%0*"PRI_USEC"%s",

>> > ../git/src/basic/time-util.c:508:46: note: directive argument in the

>> range

>> > [0, 18446744073709551614]

>> >

>> > "%s"USEC_FMT".%0*"PRI_USEC"%s",

>> >                                               ^~~~

>> >

>> > And this part doesn't seem to be fixed upstream yet.

>> >

>>

>> Its possible, that default config I build is not using this code. Do

>> you enable/disable some specific packageconfig and what arch are you

>> targetting

>>

>> > Cheers,

>> >

>> > On Mon, May 28, 2018 at 5:58 PM Khem Raj <raj.khem@gmail.com> wrote:

>> >>

>> >> Signed-off-by: Khem Raj <raj.khem@gmail.com>

>> >> ---

>> >>  ...ange-the-default-device-timeout-to-2.patch |   9 +-

>> >>  ...ation-compile-failure-by-typecasting.patch | 173 ++++++++++++++++++

>> >>  meta/recipes-core/systemd/systemd_237.bb      |   1 +

>> >>  3 files changed, 177 insertions(+), 6 deletions(-)

>> >>  create mode 100644

>> >>

>> meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>> >>

>> >> diff --git

>> >>

>> a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>> >>

>> b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>> >> index b7b1ea0886..98c83620ff 100644

>> >> ---

>> >>

>> a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>> >> +++

>> >>

>> b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>> >> @@ -1,4 +1,4 @@

>> >> -From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17 00:00:00 2001

>> >> +From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17 00:00:00 2001

>> >>  From: Khem Raj <raj.khem@gmail.com>

>> >>  Date: Mon, 14 Dec 2015 04:09:19 +0000

>> >>  Subject: [PATCH] core/device.c: Change the default device timeout to

>> 240

>> >> sec.

>> >> @@ -16,10 +16,10 @@ Signed-off-by: Khem Raj <raj.khem@gmail.com>

>> >>   1 file changed, 1 insertion(+), 1 deletion(-)

>> >>

>> >>  diff --git a/src/core/device.c b/src/core/device.c

>> >> -index 77601c552..98bf49ba2 100644

>> >> +index a43664d3b..4b16a8aec 100644

>> >>  --- a/src/core/device.c

>> >>  +++ b/src/core/device.c

>> >> -@@ -112,7 +112,7 @@ static void device_init(Unit *u) {

>> >> +@@ -113,7 +113,7 @@ static void device_init(Unit *u) {

>> >>            * indefinitely for plugged in devices, something which

>> cannot

>> >>            * happen for the other units since their operations time out

>> >>            * anyway. */

>> >> @@ -28,6 +28,3 @@ index 77601c552..98bf49ba2 100644

>> >>

>> >>           u->ignore_on_isolate = true;

>> >>   }

>> >> ---

>> >> -2.16.1

>> >> -

>> >> diff --git

>> >>

>> a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>> >>

>> b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>> >> new file mode 100644

>> >> index 0000000000..e56061f41b

>> >> --- /dev/null

>> >> +++

>> >>

>> b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>> >> @@ -0,0 +1,173 @@

>> >> +From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17 00:00:00 2001

>> >> +From: Patrick Uiterwijk <patrick@puiterwijk.org>

>> >> +Date: Thu, 22 Feb 2018 19:41:30 +0100

>> >> +Subject: [PATCH] Fix format-truncation compile failure by typecasting

>> USB

>> >> IDs

>> >> + (#8250)

>> >> +

>> >> +This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit

>> >> int, and

>> >> +uses that for parsing USB device and vendor IDs.

>> >> +

>> >> +This fixes a compile error with gcc-8 because while we know that USB

>> IDs

>> >> are 2 bytes,

>> >> +the compiler does not know that.

>> >> +

>> >> +../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output

>> may

>> >> be

>> >> +truncated writing between 4 and 8 bytes into a region of size between

>> 2

>> >> and 6

>> >> +[-Werror=format-truncation=]

>> >> +

>> >> +Upstream-Status: Backport

>> >> [

>> https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd

>> ]

>> >> +

>> >> +Signed-off-by: Adam Williamson <awilliam@redhat.com>

>> >> +Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>

>> >> +---

>> >> + src/basic/parse-util.c       | 24 ++++++++++++++++++++++

>> >> + src/basic/parse-util.h       |  2 ++

>> >> + src/test/test-parse-util.c   | 39

>> ++++++++++++++++++++++++++++++++++++

>> >> + src/udev/udev-builtin-hwdb.c | 13 ++++++------

>> >> + 4 files changed, 71 insertions(+), 7 deletions(-)

>> >> +

>> >> +diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c

>> >> +index 97533721d..ff3fc298a 100644

>> >> +--- a/src/basic/parse-util.c

>> >> ++++ b/src/basic/parse-util.c

>> >> +@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {

>> >> +         return 0;

>> >> + }

>> >> +

>> >> ++int safe_atoux16(const char *s, uint16_t *ret) {

>> >> ++        char *x = NULL;

>> >> ++        unsigned long l;

>> >> ++

>> >> ++        assert(s);

>> >> ++        assert(ret);

>> >> ++

>> >> ++        s += strspn(s, WHITESPACE);

>> >> ++

>> >> ++        errno = 0;

>> >> ++        l = strtoul(s, &x, 16);

>> >> ++        if (errno > 0)

>> >> ++                return -errno;

>> >> ++        if (!x || x == s || *x != 0)

>> >> ++                return -EINVAL;

>> >> ++        if (s[0] == '-')

>> >> ++                return -ERANGE;

>> >> ++        if ((unsigned long) (uint16_t) l != l)

>> >> ++                return -ERANGE;

>> >> ++

>> >> ++        *ret = (uint16_t) l;

>> >> ++        return 0;

>> >> ++}

>> >> ++

>> >> + int safe_atod(const char *s, double *ret_d) {

>> >> +         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;

>> >> +         char *x = NULL;

>> >> +diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h

>> >> +index 1eda1d7f9..727422056 100644

>> >> +--- a/src/basic/parse-util.h

>> >> ++++ b/src/basic/parse-util.h

>> >> +@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);

>> >> + int safe_atou16(const char *s, uint16_t *ret);

>> >> + int safe_atoi16(const char *s, int16_t *ret);

>> >> +

>> >> ++int safe_atoux16(const char *s, uint16_t *ret);

>> >> ++

>> >> + static inline int safe_atou32(const char *s, uint32_t *ret_u) {

>> >> +         assert_cc(sizeof(uint32_t) == sizeof(unsigned));

>> >> +         return safe_atou(s, (unsigned*) ret_u);

>> >> +diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c

>> >> +index 937500213..a99cea5a1 100644

>> >> +--- a/src/test/test-parse-util.c

>> >> ++++ b/src/test/test-parse-util.c

>> >> +@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {

>> >> +         assert_se(r == -EINVAL);

>> >> + }

>> >> +

>> >> ++static void test_safe_atoux16(void) {

>> >> ++        int r;

>> >> ++        uint16_t l;

>> >> ++

>> >> ++        r = safe_atoux16("1234", &l);

>> >> ++        assert_se(r == 0);

>> >> ++        assert_se(l == 0x1234);

>> >> ++

>> >> ++        r = safe_atoux16("abcd", &l);

>> >> ++        assert_se(r == 0);

>> >> ++        assert_se(l == 0xabcd);

>> >> ++

>> >> ++        r = safe_atoux16("  1234", &l);

>> >> ++        assert_se(r == 0);

>> >> ++        assert_se(l == 0x1234);

>> >> ++

>> >> ++        r = safe_atoux16("12345", &l);

>> >> ++        assert_se(r == -ERANGE);

>> >> ++

>> >> ++        r = safe_atoux16("-1", &l);

>> >> ++        assert_se(r == -ERANGE);

>> >> ++

>> >> ++        r = safe_atoux16("  -1", &l);

>> >> ++        assert_se(r == -ERANGE);

>> >> ++

>> >> ++        r = safe_atoux16("junk", &l);

>> >> ++        assert_se(r == -EINVAL);

>> >> ++

>> >> ++        r = safe_atoux16("123x", &l);

>> >> ++        assert_se(r == -EINVAL);

>> >> ++

>> >> ++        r = safe_atoux16("12.3", &l);

>> >> ++        assert_se(r == -EINVAL);

>> >> ++

>> >> ++        r = safe_atoux16("", &l);

>> >> ++        assert_se(r == -EINVAL);

>> >> ++}

>> >> ++

>> >> + static void test_safe_atou64(void) {

>> >> +         int r;

>> >> +         uint64_t l;

>> >> +@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {

>> >> +         test_safe_atolli();

>> >> +         test_safe_atou16();

>> >> +         test_safe_atoi16();

>> >> ++        test_safe_atoux16();

>> >> +         test_safe_atou64();

>> >> +         test_safe_atoi64();

>> >> +         test_safe_atod();

>> >> +diff --git a/src/udev/udev-builtin-hwdb.c

>> b/src/udev/udev-builtin-hwdb.c

>> >> +index ca7f7c230..dbfe02429 100644

>> >> +--- a/src/udev/udev-builtin-hwdb.c

>> >> ++++ b/src/udev/udev-builtin-hwdb.c

>> >> +@@ -27,6 +27,7 @@

>> >> +

>> >> + #include "alloc-util.h"

>> >> + #include "hwdb-util.h"

>> >> ++#include "parse-util.h"

>> >> + #include "string-util.h"

>> >> + #include "udev-util.h"

>> >> + #include "udev.h"

>> >> +@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct udev_device

>> *dev,

>> >> +

>> >> + static const char *modalias_usb(struct udev_device *dev, char *s,

>> size_t

>> >> size) {

>> >> +         const char *v, *p;

>> >> +-        int vn, pn;

>> >> ++        uint16_t vn, pn;

>> >> +

>> >> +         v = udev_device_get_sysattr_value(dev, "idVendor");

>> >> +         if (!v)

>> >> +@@ -71,12 +72,10 @@ static const char *modalias_usb(struct udev_device

>> >> *dev, char *s, size_t size) {

>> >> +         p = udev_device_get_sysattr_value(dev, "idProduct");

>> >> +         if (!p)

>> >> +                 return NULL;

>> >> +-        vn = strtol(v, NULL, 16);

>> >> +-        if (vn <= 0)

>> >> +-                return NULL;

>> >> +-        pn = strtol(p, NULL, 16);

>> >> +-        if (pn <= 0)

>> >> +-                return NULL;

>> >> ++        if (safe_atoux16(v, &vn) < 0)

>> >> ++              return NULL;

>> >> ++        if (safe_atoux16(p, &pn) < 0)

>> >> ++              return NULL;

>> >> +         snprintf(s, size, "usb:v%04Xp%04X*", vn, pn);

>> >> +         return s;

>> >> + }

>> >> +--

>> >> +2.17.0

>> >> +

>> >> diff --git a/meta/recipes-core/systemd/systemd_237.bb

>> >> b/meta/recipes-core/systemd/systemd_237.bb

>> >> index b7c2113255..c4743a6b9d 100644

>> >> --- a/meta/recipes-core/systemd/systemd_237.bb

>> >> +++ b/meta/recipes-core/systemd/systemd_237.bb

>> >> @@ -52,6 +52,7 @@ SRC_URI += "file://touchscreen.rules \

>> >>             file://0032-memfd.patch \

>> >>

>> >> file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \

>> >>             file://libmount.patch \

>> >> +

>> >> file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>> \

>> >>             "

>> >>  SRC_URI_append_qemuall = "

>> >> file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"

>> >>

>> >> --

>> >> 2.17.0

>> >>

>> >> --

>> >> _______________________________________________

>> >> Openembedded-core mailing list

>> >> Openembedded-core@lists.openembedded.org

>> >> http://lists.openembedded.org/mailman/listinfo/openembedded-core

>>

>
<div dir="ltr">It fails when -O1 or -Os is being used, builds ok with -O0, -O2, -O3.<div><br></div><div>Checking a bit more shows that it doesn&#39;t fail when -ftree-vrp is used, probably because this check is removed as the documentation for -ftree-vrp says:</div><div><br></div><div><div>-ftree-vrp</div><div>Perform Value Range Propagation on trees. This is similar to the constant propagation pass, but instead of values, ranges of values are propagated. This allows the optimizers to remove unnecessary range checks like array bound checks and null pointer checks. This is enabled by default at -O2 and higher. Null pointer check elimination is only done if -fdelete-null-pointer-checks is enabled.</div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 1, 2018 at 4:01 PM Martin Jansa &lt;<a href="mailto:martin.jansa@gmail.com">martin.jansa@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>No change in PACKAGECONFIG, just default nodistro qemux86 with added systemd and debug build:</div><div><div>DISTRO_FEATURES_append = &quot; systemd&quot;</div><div>DEBUG_BUILD = &quot;1&quot;</div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 31, 2018 at 6:17 PM Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, May 31, 2018 at 9:05 AM, Martin Jansa &lt;<a href="mailto:martin.jansa@gmail.com" target="_blank">martin.jansa@gmail.com</a>&gt; wrote:<br>
&gt; Unlike the previous version you had in your RFT branch (which added<br>
&gt; -Wno-error=format-truncation) this doesn&#39;t seem to be complete fix.<br>
&gt;<br>
&gt; In qemux86 build which already includes this change I&#39;m seeing:<br>
&gt; ../git/src/basic/time-util.c: In function &#39;format_timespan&#39;:<br>
&gt; ../git/src/basic/time-util.c:508:46: error: &#39;%0*llu&#39; directive output<br>
&gt; between 1 and 2147483647 bytes may cause result to exceed &#39;INT_MAX&#39;<br>
&gt; [-Werror=format-truncation=]<br>
&gt;<br>
&gt; &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,<br>
&gt;                                               ^~~~<br>
&gt; ../git/src/basic/time-util.c:508:60: note: format string is defined here<br>
&gt;<br>
&gt; &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,<br>
&gt; ../git/src/basic/time-util.c:508:46: note: directive argument in the range<br>
&gt; [0, 18446744073709551614]<br>
&gt;<br>
&gt; &quot;%s&quot;USEC_FMT&quot;.%0*&quot;PRI_USEC&quot;%s&quot;,<br>
&gt;                                               ^~~~<br>
&gt;<br>
&gt; And this part doesn&#39;t seem to be fixed upstream yet.<br>
&gt;<br>
<br>
Its possible, that default config I build is not using this code. Do<br>
you enable/disable some specific packageconfig and what arch are you<br>
targetting<br>
<br>
&gt; Cheers,<br>
&gt;<br>
&gt; On Mon, May 28, 2018 at 5:58 PM Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Signed-off-by: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
&gt;&gt; ---<br>
&gt;&gt;  ...ange-the-default-device-timeout-to-2.patch |   9 +-<br>
&gt;&gt;  ...ation-compile-failure-by-typecasting.patch | 173 ++++++++++++++++++<br>
&gt;&gt;  meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a>      |   1 +<br>
&gt;&gt;  3 files changed, 177 insertions(+), 6 deletions(-)<br>
&gt;&gt;  create mode 100644<br>
&gt;&gt; meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
&gt;&gt;<br>
&gt;&gt; diff --git<br>
&gt;&gt; a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
&gt;&gt; b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
&gt;&gt; index b7b1ea0886..98c83620ff 100644<br>
&gt;&gt; ---<br>
&gt;&gt; a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
&gt;&gt; +++<br>
&gt;&gt; b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch<br>
&gt;&gt; @@ -1,4 +1,4 @@<br>
&gt;&gt; -From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17 00:00:00 2001<br>
&gt;&gt; +From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17 00:00:00 2001<br>
&gt;&gt;  From: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
&gt;&gt;  Date: Mon, 14 Dec 2015 04:09:19 +0000<br>
&gt;&gt;  Subject: [PATCH] core/device.c: Change the default device timeout to 240<br>
&gt;&gt; sec.<br>
&gt;&gt; @@ -16,10 +16,10 @@ Signed-off-by: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>
&gt;&gt;   1 file changed, 1 insertion(+), 1 deletion(-)<br>
&gt;&gt;<br>
&gt;&gt;  diff --git a/src/core/device.c b/src/core/device.c<br>
&gt;&gt; -index 77601c552..98bf49ba2 100644<br>
&gt;&gt; +index a43664d3b..4b16a8aec 100644<br>
&gt;&gt;  --- a/src/core/device.c<br>
&gt;&gt;  +++ b/src/core/device.c<br>
&gt;&gt; -@@ -112,7 +112,7 @@ static void device_init(Unit *u) {<br>
&gt;&gt; +@@ -113,7 +113,7 @@ static void device_init(Unit *u) {<br>
&gt;&gt;            * indefinitely for plugged in devices, something which cannot<br>
&gt;&gt;            * happen for the other units since their operations time out<br>
&gt;&gt;            * anyway. */<br>
&gt;&gt; @@ -28,6 +28,3 @@ index 77601c552..98bf49ba2 100644<br>
&gt;&gt;<br>
&gt;&gt;           u-&gt;ignore_on_isolate = true;<br>
&gt;&gt;   }<br>
&gt;&gt; ---<br>
&gt;&gt; -2.16.1<br>
&gt;&gt; -<br>
&gt;&gt; diff --git<br>
&gt;&gt; a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
&gt;&gt; b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
&gt;&gt; new file mode 100644<br>
&gt;&gt; index 0000000000..e56061f41b<br>
&gt;&gt; --- /dev/null<br>
&gt;&gt; +++<br>
&gt;&gt; b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch<br>
&gt;&gt; @@ -0,0 +1,173 @@<br>
&gt;&gt; +From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17 00:00:00 2001<br>
&gt;&gt; +From: Patrick Uiterwijk &lt;<a href="mailto:patrick@puiterwijk.org" target="_blank">patrick@puiterwijk.org</a>&gt;<br>
&gt;&gt; +Date: Thu, 22 Feb 2018 19:41:30 +0100<br>
&gt;&gt; +Subject: [PATCH] Fix format-truncation compile failure by typecasting USB<br>
&gt;&gt; IDs<br>
&gt;&gt; + (#8250)<br>
&gt;&gt; +<br>
&gt;&gt; +This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit<br>
&gt;&gt; int, and<br>
&gt;&gt; +uses that for parsing USB device and vendor IDs.<br>
&gt;&gt; +<br>
&gt;&gt; +This fixes a compile error with gcc-8 because while we know that USB IDs<br>
&gt;&gt; are 2 bytes,<br>
&gt;&gt; +the compiler does not know that.<br>
&gt;&gt; +<br>
&gt;&gt; +../src/udev/udev-builtin-hwdb.c:80:38: error: &#39;%04X&#39; directive output may<br>
&gt;&gt; be<br>
&gt;&gt; +truncated writing between 4 and 8 bytes into a region of size between 2<br>
&gt;&gt; and 6<br>
&gt;&gt; +[-Werror=format-truncation=]<br>
&gt;&gt; +<br>
&gt;&gt; +Upstream-Status: Backport<br>
&gt;&gt; [<a href="https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd" rel="noreferrer" target="_blank">https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd</a>]<br>
&gt;&gt; +<br>
&gt;&gt; +Signed-off-by: Adam Williamson &lt;<a href="mailto:awilliam@redhat.com" target="_blank">awilliam@redhat.com</a>&gt;<br>
&gt;&gt; +Signed-off-by: Patrick Uiterwijk &lt;<a href="mailto:puiterwijk@redhat.com" target="_blank">puiterwijk@redhat.com</a>&gt;<br>
&gt;&gt; +---<br>
&gt;&gt; + src/basic/parse-util.c       | 24 ++++++++++++++++++++++<br>
&gt;&gt; + src/basic/parse-util.h       |  2 ++<br>
&gt;&gt; + src/test/test-parse-util.c   | 39 ++++++++++++++++++++++++++++++++++++<br>
&gt;&gt; + src/udev/udev-builtin-hwdb.c | 13 ++++++------<br>
&gt;&gt; + 4 files changed, 71 insertions(+), 7 deletions(-)<br>
&gt;&gt; +<br>
&gt;&gt; +diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c<br>
&gt;&gt; +index 97533721d..ff3fc298a 100644<br>
&gt;&gt; +--- a/src/basic/parse-util.c<br>
&gt;&gt; ++++ b/src/basic/parse-util.c<br>
&gt;&gt; +@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {<br>
&gt;&gt; +         return 0;<br>
&gt;&gt; + }<br>
&gt;&gt; +<br>
&gt;&gt; ++int safe_atoux16(const char *s, uint16_t *ret) {<br>
&gt;&gt; ++        char *x = NULL;<br>
&gt;&gt; ++        unsigned long l;<br>
&gt;&gt; ++<br>
&gt;&gt; ++        assert(s);<br>
&gt;&gt; ++        assert(ret);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        s += strspn(s, WHITESPACE);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        errno = 0;<br>
&gt;&gt; ++        l = strtoul(s, &amp;x, 16);<br>
&gt;&gt; ++        if (errno &gt; 0)<br>
&gt;&gt; ++                return -errno;<br>
&gt;&gt; ++        if (!x || x == s || *x != 0)<br>
&gt;&gt; ++                return -EINVAL;<br>
&gt;&gt; ++        if (s[0] == &#39;-&#39;)<br>
&gt;&gt; ++                return -ERANGE;<br>
&gt;&gt; ++        if ((unsigned long) (uint16_t) l != l)<br>
&gt;&gt; ++                return -ERANGE;<br>
&gt;&gt; ++<br>
&gt;&gt; ++        *ret = (uint16_t) l;<br>
&gt;&gt; ++        return 0;<br>
&gt;&gt; ++}<br>
&gt;&gt; ++<br>
&gt;&gt; + int safe_atod(const char *s, double *ret_d) {<br>
&gt;&gt; +         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;<br>
&gt;&gt; +         char *x = NULL;<br>
&gt;&gt; +diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h<br>
&gt;&gt; +index 1eda1d7f9..727422056 100644<br>
&gt;&gt; +--- a/src/basic/parse-util.h<br>
&gt;&gt; ++++ b/src/basic/parse-util.h<br>
&gt;&gt; +@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);<br>
&gt;&gt; + int safe_atou16(const char *s, uint16_t *ret);<br>
&gt;&gt; + int safe_atoi16(const char *s, int16_t *ret);<br>
&gt;&gt; +<br>
&gt;&gt; ++int safe_atoux16(const char *s, uint16_t *ret);<br>
&gt;&gt; ++<br>
&gt;&gt; + static inline int safe_atou32(const char *s, uint32_t *ret_u) {<br>
&gt;&gt; +         assert_cc(sizeof(uint32_t) == sizeof(unsigned));<br>
&gt;&gt; +         return safe_atou(s, (unsigned*) ret_u);<br>
&gt;&gt; +diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c<br>
&gt;&gt; +index 937500213..a99cea5a1 100644<br>
&gt;&gt; +--- a/src/test/test-parse-util.c<br>
&gt;&gt; ++++ b/src/test/test-parse-util.c<br>
&gt;&gt; +@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {<br>
&gt;&gt; +         assert_se(r == -EINVAL);<br>
&gt;&gt; + }<br>
&gt;&gt; +<br>
&gt;&gt; ++static void test_safe_atoux16(void) {<br>
&gt;&gt; ++        int r;<br>
&gt;&gt; ++        uint16_t l;<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;1234&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == 0);<br>
&gt;&gt; ++        assert_se(l == 0x1234);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;abcd&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == 0);<br>
&gt;&gt; ++        assert_se(l == 0xabcd);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;  1234&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == 0);<br>
&gt;&gt; ++        assert_se(l == 0x1234);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;12345&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -ERANGE);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;-1&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -ERANGE);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;  -1&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -ERANGE);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;junk&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -EINVAL);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;123x&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -EINVAL);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;12.3&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -EINVAL);<br>
&gt;&gt; ++<br>
&gt;&gt; ++        r = safe_atoux16(&quot;&quot;, &amp;l);<br>
&gt;&gt; ++        assert_se(r == -EINVAL);<br>
&gt;&gt; ++}<br>
&gt;&gt; ++<br>
&gt;&gt; + static void test_safe_atou64(void) {<br>
&gt;&gt; +         int r;<br>
&gt;&gt; +         uint64_t l;<br>
&gt;&gt; +@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {<br>
&gt;&gt; +         test_safe_atolli();<br>
&gt;&gt; +         test_safe_atou16();<br>
&gt;&gt; +         test_safe_atoi16();<br>
&gt;&gt; ++        test_safe_atoux16();<br>
&gt;&gt; +         test_safe_atou64();<br>
&gt;&gt; +         test_safe_atoi64();<br>
&gt;&gt; +         test_safe_atod();<br>
&gt;&gt; +diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c<br>
&gt;&gt; +index ca7f7c230..dbfe02429 100644<br>
&gt;&gt; +--- a/src/udev/udev-builtin-hwdb.c<br>
&gt;&gt; ++++ b/src/udev/udev-builtin-hwdb.c<br>
&gt;&gt; +@@ -27,6 +27,7 @@<br>
&gt;&gt; +<br>
&gt;&gt; + #include &quot;alloc-util.h&quot;<br>
&gt;&gt; + #include &quot;hwdb-util.h&quot;<br>
&gt;&gt; ++#include &quot;parse-util.h&quot;<br>
&gt;&gt; + #include &quot;string-util.h&quot;<br>
&gt;&gt; + #include &quot;udev-util.h&quot;<br>
&gt;&gt; + #include &quot;udev.h&quot;<br>
&gt;&gt; +@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev,<br>
&gt;&gt; +<br>
&gt;&gt; + static const char *modalias_usb(struct udev_device *dev, char *s, size_t<br>
&gt;&gt; size) {<br>
&gt;&gt; +         const char *v, *p;<br>
&gt;&gt; +-        int vn, pn;<br>
&gt;&gt; ++        uint16_t vn, pn;<br>
&gt;&gt; +<br>
&gt;&gt; +         v = udev_device_get_sysattr_value(dev, &quot;idVendor&quot;);<br>
&gt;&gt; +         if (!v)<br>
&gt;&gt; +@@ -71,12 +72,10 @@ static const char *modalias_usb(struct udev_device<br>
&gt;&gt; *dev, char *s, size_t size) {<br>
&gt;&gt; +         p = udev_device_get_sysattr_value(dev, &quot;idProduct&quot;);<br>
&gt;&gt; +         if (!p)<br>
&gt;&gt; +                 return NULL;<br>
&gt;&gt; +-        vn = strtol(v, NULL, 16);<br>
&gt;&gt; +-        if (vn &lt;= 0)<br>
&gt;&gt; +-                return NULL;<br>
&gt;&gt; +-        pn = strtol(p, NULL, 16);<br>
&gt;&gt; +-        if (pn &lt;= 0)<br>
&gt;&gt; +-                return NULL;<br>
&gt;&gt; ++        if (safe_atoux16(v, &amp;vn) &lt; 0)<br>
&gt;&gt; ++              return NULL;<br>
&gt;&gt; ++        if (safe_atoux16(p, &amp;pn) &lt; 0)<br>
&gt;&gt; ++              return NULL;<br>
&gt;&gt; +         snprintf(s, size, &quot;usb:v%04Xp%04X*&quot;, vn, pn);<br>
&gt;&gt; +         return s;<br>
&gt;&gt; + }<br>
&gt;&gt; +--<br>
&gt;&gt; +2.17.0<br>
&gt;&gt; +<br>
&gt;&gt; diff --git a/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
&gt;&gt; b/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
&gt;&gt; index b7c2113255..c4743a6b9d 100644<br>
&gt;&gt; --- a/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
&gt;&gt; +++ b/meta/recipes-core/systemd/<a href="http://systemd_237.bb" rel="noreferrer" target="_blank">systemd_237.bb</a><br>
&gt;&gt; @@ -52,6 +52,7 @@ SRC_URI += &quot;file://touchscreen.rules \<br>
&gt;&gt;             file://0032-memfd.patch \<br>
&gt;&gt;<br>
&gt;&gt; file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \<br>
&gt;&gt;             file://libmount.patch \<br>
&gt;&gt; +<br>
&gt;&gt; file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \<br>
&gt;&gt;             &quot;<br>
&gt;&gt;  SRC_URI_append_qemuall = &quot;<br>
&gt;&gt; file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch&quot;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; 2.17.0<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Openembedded-core mailing list<br>
&gt;&gt; <a href="mailto:Openembedded-core@lists.openembedded.org" target="_blank">Openembedded-core@lists.openembedded.org</a><br>
&gt;&gt; <a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/mailman/listinfo/openembedded-core</a><br>
</blockquote></div>
</blockquote></div>
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Khem Raj June 1, 2018, 5:09 p.m. UTC | #5
On 6/1/18 7:01 AM, Martin Jansa wrote:
> No change in PACKAGECONFIG, just default nodistro qemux86 with added

> systemd and debug build:

> DISTRO_FEATURES_append = " systemd"

> DEBUG_BUILD = "1"

> 


hmm so must be some code which is eliminated by compiler optimizations
with -O2 since with debug build it will use -O1

> 

> On Thu, May 31, 2018 at 6:17 PM Khem Raj <raj.khem@gmail.com

> <mailto:raj.khem@gmail.com>> wrote:

> 

>     On Thu, May 31, 2018 at 9:05 AM, Martin Jansa

>     <martin.jansa@gmail.com <mailto:martin.jansa@gmail.com>> wrote:

>     > Unlike the previous version you had in your RFT branch (which added

>     > -Wno-error=format-truncation) this doesn't seem to be complete fix.

>     >

>     > In qemux86 build which already includes this change I'm seeing:

>     > ../git/src/basic/time-util.c: In function 'format_timespan':

>     > ../git/src/basic/time-util.c:508:46: error: '%0*llu' directive output

>     > between 1 and 2147483647 bytes may cause result to exceed 'INT_MAX'

>     > [-Werror=format-truncation=]

>     >

>     > "%s"USEC_FMT".%0*"PRI_USEC"%s",

>     >                                               ^~~~

>     > ../git/src/basic/time-util.c:508:60: note: format string is

>     defined here

>     >

>     > "%s"USEC_FMT".%0*"PRI_USEC"%s",

>     > ../git/src/basic/time-util.c:508:46: note: directive argument in

>     the range

>     > [0, 18446744073709551614]

>     >

>     > "%s"USEC_FMT".%0*"PRI_USEC"%s",

>     >                                               ^~~~

>     >

>     > And this part doesn't seem to be fixed upstream yet.

>     >

> 

>     Its possible, that default config I build is not using this code. Do

>     you enable/disable some specific packageconfig and what arch are you

>     targetting

> 

>     > Cheers,

>     >

>     > On Mon, May 28, 2018 at 5:58 PM Khem Raj <raj.khem@gmail.com

>     <mailto:raj.khem@gmail.com>> wrote:

>     >>

>     >> Signed-off-by: Khem Raj <raj.khem@gmail.com

>     <mailto:raj.khem@gmail.com>>

>     >> ---

>     >>  ...ange-the-default-device-timeout-to-2.patch |   9 +-

>     >>  ...ation-compile-failure-by-typecasting.patch | 173

>     ++++++++++++++++++

>     >>  meta/recipes-core/systemd/systemd_237.bb

>     <http://systemd_237.bb>      |   1 +

>     >>  3 files changed, 177 insertions(+), 6 deletions(-)

>     >>  create mode 100644

>     >>

>     meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>     >>

>     >> diff --git

>     >>

>     a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>     >>

>     b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>     >> index b7b1ea0886..98c83620ff 100644

>     >> ---

>     >>

>     a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>     >> +++

>     >>

>     b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch

>     >> @@ -1,4 +1,4 @@

>     >> -From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17

>     00:00:00 2001

>     >> +From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17

>     00:00:00 2001

>     >>  From: Khem Raj <raj.khem@gmail.com <mailto:raj.khem@gmail.com>>

>     >>  Date: Mon, 14 Dec 2015 04:09:19 +0000

>     >>  Subject: [PATCH] core/device.c: Change the default device

>     timeout to 240

>     >> sec.

>     >> @@ -16,10 +16,10 @@ Signed-off-by: Khem Raj <raj.khem@gmail.com

>     <mailto:raj.khem@gmail.com>>

>     >>   1 file changed, 1 insertion(+), 1 deletion(-)

>     >>

>     >>  diff --git a/src/core/device.c b/src/core/device.c

>     >> -index 77601c552..98bf49ba2 100644

>     >> +index a43664d3b..4b16a8aec 100644

>     >>  --- a/src/core/device.c

>     >>  +++ b/src/core/device.c

>     >> -@@ -112,7 +112,7 @@ static void device_init(Unit *u) {

>     >> +@@ -113,7 +113,7 @@ static void device_init(Unit *u) {

>     >>            * indefinitely for plugged in devices, something which

>     cannot

>     >>            * happen for the other units since their operations

>     time out

>     >>            * anyway. */

>     >> @@ -28,6 +28,3 @@ index 77601c552..98bf49ba2 100644

>     >>

>     >>           u->ignore_on_isolate = true;

>     >>   }

>     >> ---

>     >> -2.16.1

>     >> -

>     >> diff --git

>     >>

>     a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>     >>

>     b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>     >> new file mode 100644

>     >> index 0000000000..e56061f41b

>     >> --- /dev/null

>     >> +++

>     >>

>     b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch

>     >> @@ -0,0 +1,173 @@

>     >> +From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17

>     00:00:00 2001

>     >> +From: Patrick Uiterwijk <patrick@puiterwijk.org

>     <mailto:patrick@puiterwijk.org>>

>     >> +Date: Thu, 22 Feb 2018 19:41:30 +0100

>     >> +Subject: [PATCH] Fix format-truncation compile failure by

>     typecasting USB

>     >> IDs

>     >> + (#8250)

>     >> +

>     >> +This patch adds safe_atoux16 for parsing an unsigned hexadecimal

>     16bit

>     >> int, and

>     >> +uses that for parsing USB device and vendor IDs.

>     >> +

>     >> +This fixes a compile error with gcc-8 because while we know that

>     USB IDs

>     >> are 2 bytes,

>     >> +the compiler does not know that.

>     >> +

>     >> +../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive

>     output may

>     >> be

>     >> +truncated writing between 4 and 8 bytes into a region of size

>     between 2

>     >> and 6

>     >> +[-Werror=format-truncation=]

>     >> +

>     >> +Upstream-Status: Backport

>     >>

>     [https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd]

>     >> +

>     >> +Signed-off-by: Adam Williamson <awilliam@redhat.com

>     <mailto:awilliam@redhat.com>>

>     >> +Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com

>     <mailto:puiterwijk@redhat.com>>

>     >> +---

>     >> + src/basic/parse-util.c       | 24 ++++++++++++++++++++++

>     >> + src/basic/parse-util.h       |  2 ++

>     >> + src/test/test-parse-util.c   | 39

>     ++++++++++++++++++++++++++++++++++++

>     >> + src/udev/udev-builtin-hwdb.c | 13 ++++++------

>     >> + 4 files changed, 71 insertions(+), 7 deletions(-)

>     >> +

>     >> +diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c

>     >> +index 97533721d..ff3fc298a 100644

>     >> +--- a/src/basic/parse-util.c

>     >> ++++ b/src/basic/parse-util.c

>     >> +@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {

>     >> +         return 0;

>     >> + }

>     >> +

>     >> ++int safe_atoux16(const char *s, uint16_t *ret) {

>     >> ++        char *x = NULL;

>     >> ++        unsigned long l;

>     >> ++

>     >> ++        assert(s);

>     >> ++        assert(ret);

>     >> ++

>     >> ++        s += strspn(s, WHITESPACE);

>     >> ++

>     >> ++        errno = 0;

>     >> ++        l = strtoul(s, &x, 16);

>     >> ++        if (errno > 0)

>     >> ++                return -errno;

>     >> ++        if (!x || x == s || *x != 0)

>     >> ++                return -EINVAL;

>     >> ++        if (s[0] == '-')

>     >> ++                return -ERANGE;

>     >> ++        if ((unsigned long) (uint16_t) l != l)

>     >> ++                return -ERANGE;

>     >> ++

>     >> ++        *ret = (uint16_t) l;

>     >> ++        return 0;

>     >> ++}

>     >> ++

>     >> + int safe_atod(const char *s, double *ret_d) {

>     >> +         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;

>     >> +         char *x = NULL;

>     >> +diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h

>     >> +index 1eda1d7f9..727422056 100644

>     >> +--- a/src/basic/parse-util.h

>     >> ++++ b/src/basic/parse-util.h

>     >> +@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);

>     >> + int safe_atou16(const char *s, uint16_t *ret);

>     >> + int safe_atoi16(const char *s, int16_t *ret);

>     >> +

>     >> ++int safe_atoux16(const char *s, uint16_t *ret);

>     >> ++

>     >> + static inline int safe_atou32(const char *s, uint32_t *ret_u) {

>     >> +         assert_cc(sizeof(uint32_t) == sizeof(unsigned));

>     >> +         return safe_atou(s, (unsigned*) ret_u);

>     >> +diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c

>     >> +index 937500213..a99cea5a1 100644

>     >> +--- a/src/test/test-parse-util.c

>     >> ++++ b/src/test/test-parse-util.c

>     >> +@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {

>     >> +         assert_se(r == -EINVAL);

>     >> + }

>     >> +

>     >> ++static void test_safe_atoux16(void) {

>     >> ++        int r;

>     >> ++        uint16_t l;

>     >> ++

>     >> ++        r = safe_atoux16("1234", &l);

>     >> ++        assert_se(r == 0);

>     >> ++        assert_se(l == 0x1234);

>     >> ++

>     >> ++        r = safe_atoux16("abcd", &l);

>     >> ++        assert_se(r == 0);

>     >> ++        assert_se(l == 0xabcd);

>     >> ++

>     >> ++        r = safe_atoux16("  1234", &l);

>     >> ++        assert_se(r == 0);

>     >> ++        assert_se(l == 0x1234);

>     >> ++

>     >> ++        r = safe_atoux16("12345", &l);

>     >> ++        assert_se(r == -ERANGE);

>     >> ++

>     >> ++        r = safe_atoux16("-1", &l);

>     >> ++        assert_se(r == -ERANGE);

>     >> ++

>     >> ++        r = safe_atoux16("  -1", &l);

>     >> ++        assert_se(r == -ERANGE);

>     >> ++

>     >> ++        r = safe_atoux16("junk", &l);

>     >> ++        assert_se(r == -EINVAL);

>     >> ++

>     >> ++        r = safe_atoux16("123x", &l);

>     >> ++        assert_se(r == -EINVAL);

>     >> ++

>     >> ++        r = safe_atoux16("12.3", &l);

>     >> ++        assert_se(r == -EINVAL);

>     >> ++

>     >> ++        r = safe_atoux16("", &l);

>     >> ++        assert_se(r == -EINVAL);

>     >> ++}

>     >> ++

>     >> + static void test_safe_atou64(void) {

>     >> +         int r;

>     >> +         uint64_t l;

>     >> +@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {

>     >> +         test_safe_atolli();

>     >> +         test_safe_atou16();

>     >> +         test_safe_atoi16();

>     >> ++        test_safe_atoux16();

>     >> +         test_safe_atou64();

>     >> +         test_safe_atoi64();

>     >> +         test_safe_atod();

>     >> +diff --git a/src/udev/udev-builtin-hwdb.c

>     b/src/udev/udev-builtin-hwdb.c

>     >> +index ca7f7c230..dbfe02429 100644

>     >> +--- a/src/udev/udev-builtin-hwdb.c

>     >> ++++ b/src/udev/udev-builtin-hwdb.c

>     >> +@@ -27,6 +27,7 @@

>     >> +

>     >> + #include "alloc-util.h"

>     >> + #include "hwdb-util.h"

>     >> ++#include "parse-util.h"

>     >> + #include "string-util.h"

>     >> + #include "udev-util.h"

>     >> + #include "udev.h"

>     >> +@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct

>     udev_device *dev,

>     >> +

>     >> + static const char *modalias_usb(struct udev_device *dev, char

>     *s, size_t

>     >> size) {

>     >> +         const char *v, *p;

>     >> +-        int vn, pn;

>     >> ++        uint16_t vn, pn;

>     >> +

>     >> +         v = udev_device_get_sysattr_value(dev, "idVendor");

>     >> +         if (!v)

>     >> +@@ -71,12 +72,10 @@ static const char *modalias_usb(struct

>     udev_device

>     >> *dev, char *s, size_t size) {

>     >> +         p = udev_device_get_sysattr_value(dev, "idProduct");

>     >> +         if (!p)

>     >> +                 return NULL;

>     >> +-        vn = strtol(v, NULL, 16);

>     >> +-        if (vn <= 0)

>     >> +-                return NULL;

>     >> +-        pn = strtol(p, NULL, 16);

>     >> +-        if (pn <= 0)

>     >> +-                return NULL;

>     >> ++        if (safe_atoux16(v, &vn) < 0)

>     >> ++              return NULL;

>     >> ++        if (safe_atoux16(p, &pn) < 0)

>     >> ++              return NULL;

>     >> +         snprintf(s, size, "usb:v%04Xp%04X*", vn, pn);

>     >> +         return s;

>     >> + }

>     >> +--

>     >> +2.17.0

>     >> +

>     >> diff --git a/meta/recipes-core/systemd/systemd_237.bb

>     <http://systemd_237.bb>

>     >> b/meta/recipes-core/systemd/systemd_237.bb <http://systemd_237.bb>

>     >> index b7c2113255..c4743a6b9d 100644

>     >> --- a/meta/recipes-core/systemd/systemd_237.bb

>     <http://systemd_237.bb>

>     >> +++ b/meta/recipes-core/systemd/systemd_237.bb

>     <http://systemd_237.bb>

>     >> @@ -52,6 +52,7 @@ SRC_URI += "file://touchscreen.rules \

>     >>             file://0032-memfd.patch \

>     >>

>     >> file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \

>     >>             file://libmount.patch \

>     >> +

>     >>

>     file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \

>     >>             "

>     >>  SRC_URI_append_qemuall = "

>     >>

>     file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"

>     >>

>     >> --

>     >> 2.17.0

>     >>

>     >> --

>     >> _______________________________________________

>     >> Openembedded-core mailing list

>     >> Openembedded-core@lists.openembedded.org

>     <mailto:Openembedded-core@lists.openembedded.org>

>     >> http://lists.openembedded.org/mailman/listinfo/openembedded-core

>
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
diff mbox series

Patch

diff --git a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch
index b7b1ea0886..98c83620ff 100644
--- a/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch
+++ b/meta/recipes-core/systemd/systemd/0001-core-device.c-Change-the-default-device-timeout-to-2.patch
@@ -1,4 +1,4 @@ 
-From 9820c165a9e559cf851e3beb60fad2571de4ded2 Mon Sep 17 00:00:00 2001
+From 7844e070745611a52e355b73e7890f360dd540d0 Mon Sep 17 00:00:00 2001
 From: Khem Raj <raj.khem@gmail.com>
 Date: Mon, 14 Dec 2015 04:09:19 +0000
 Subject: [PATCH] core/device.c: Change the default device timeout to 240 sec.
@@ -16,10 +16,10 @@  Signed-off-by: Khem Raj <raj.khem@gmail.com>
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/src/core/device.c b/src/core/device.c
-index 77601c552..98bf49ba2 100644
+index a43664d3b..4b16a8aec 100644
 --- a/src/core/device.c
 +++ b/src/core/device.c
-@@ -112,7 +112,7 @@ static void device_init(Unit *u) {
+@@ -113,7 +113,7 @@ static void device_init(Unit *u) {
           * indefinitely for plugged in devices, something which cannot
           * happen for the other units since their operations time out
           * anyway. */
@@ -28,6 +28,3 @@  index 77601c552..98bf49ba2 100644
  
          u->ignore_on_isolate = true;
  }
--- 
-2.16.1
-
diff --git a/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch
new file mode 100644
index 0000000000..e56061f41b
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0034-Fix-format-truncation-compile-failure-by-typecasting.patch
@@ -0,0 +1,173 @@ 
+From c2b3ebe112ebfd9f9e82fb1531ee225c3152ca83 Mon Sep 17 00:00:00 2001
+From: Patrick Uiterwijk <patrick@puiterwijk.org>
+Date: Thu, 22 Feb 2018 19:41:30 +0100
+Subject: [PATCH] Fix format-truncation compile failure by typecasting USB IDs
+ (#8250)
+
+This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit int, and
+uses that for parsing USB device and vendor IDs.
+
+This fixes a compile error with gcc-8 because while we know that USB IDs are 2 bytes,
+the compiler does not know that.
+
+../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may be
+truncated writing between 4 and 8 bytes into a region of size between 2 and 6
+[-Werror=format-truncation=]
+
+Upstream-Status: Backport [https://github.com/systemd/systemd/commit/5547c12503a683290eaed47954ffcfb2d1bc03cd]
+
+Signed-off-by: Adam Williamson <awilliam@redhat.com>
+Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
+---
+ src/basic/parse-util.c       | 24 ++++++++++++++++++++++
+ src/basic/parse-util.h       |  2 ++
+ src/test/test-parse-util.c   | 39 ++++++++++++++++++++++++++++++++++++
+ src/udev/udev-builtin-hwdb.c | 13 ++++++------
+ 4 files changed, 71 insertions(+), 7 deletions(-)
+
+diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
+index 97533721d..ff3fc298a 100644
+--- a/src/basic/parse-util.c
++++ b/src/basic/parse-util.c
+@@ -532,6 +532,30 @@ int safe_atoi16(const char *s, int16_t *ret) {
+         return 0;
+ }
+ 
++int safe_atoux16(const char *s, uint16_t *ret) {
++        char *x = NULL;
++        unsigned long l;
++
++        assert(s);
++        assert(ret);
++
++        s += strspn(s, WHITESPACE);
++
++        errno = 0;
++        l = strtoul(s, &x, 16);
++        if (errno > 0)
++                return -errno;
++        if (!x || x == s || *x != 0)
++                return -EINVAL;
++        if (s[0] == '-')
++                return -ERANGE;
++        if ((unsigned long) (uint16_t) l != l)
++                return -ERANGE;
++
++        *ret = (uint16_t) l;
++        return 0;
++}
++
+ int safe_atod(const char *s, double *ret_d) {
+         _cleanup_(freelocalep) locale_t loc = (locale_t) 0;
+         char *x = NULL;
+diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h
+index 1eda1d7f9..727422056 100644
+--- a/src/basic/parse-util.h
++++ b/src/basic/parse-util.h
+@@ -54,6 +54,8 @@ int safe_atou8(const char *s, uint8_t *ret);
+ int safe_atou16(const char *s, uint16_t *ret);
+ int safe_atoi16(const char *s, int16_t *ret);
+ 
++int safe_atoux16(const char *s, uint16_t *ret);
++
+ static inline int safe_atou32(const char *s, uint32_t *ret_u) {
+         assert_cc(sizeof(uint32_t) == sizeof(unsigned));
+         return safe_atou(s, (unsigned*) ret_u);
+diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c
+index 937500213..a99cea5a1 100644
+--- a/src/test/test-parse-util.c
++++ b/src/test/test-parse-util.c
+@@ -468,6 +468,44 @@ static void test_safe_atoi16(void) {
+         assert_se(r == -EINVAL);
+ }
+ 
++static void test_safe_atoux16(void) {
++        int r;
++        uint16_t l;
++
++        r = safe_atoux16("1234", &l);
++        assert_se(r == 0);
++        assert_se(l == 0x1234);
++
++        r = safe_atoux16("abcd", &l);
++        assert_se(r == 0);
++        assert_se(l == 0xabcd);
++
++        r = safe_atoux16("  1234", &l);
++        assert_se(r == 0);
++        assert_se(l == 0x1234);
++
++        r = safe_atoux16("12345", &l);
++        assert_se(r == -ERANGE);
++
++        r = safe_atoux16("-1", &l);
++        assert_se(r == -ERANGE);
++
++        r = safe_atoux16("  -1", &l);
++        assert_se(r == -ERANGE);
++
++        r = safe_atoux16("junk", &l);
++        assert_se(r == -EINVAL);
++
++        r = safe_atoux16("123x", &l);
++        assert_se(r == -EINVAL);
++
++        r = safe_atoux16("12.3", &l);
++        assert_se(r == -EINVAL);
++
++        r = safe_atoux16("", &l);
++        assert_se(r == -EINVAL);
++}
++
+ static void test_safe_atou64(void) {
+         int r;
+         uint64_t l;
+@@ -745,6 +783,7 @@ int main(int argc, char *argv[]) {
+         test_safe_atolli();
+         test_safe_atou16();
+         test_safe_atoi16();
++        test_safe_atoux16();
+         test_safe_atou64();
+         test_safe_atoi64();
+         test_safe_atod();
+diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c
+index ca7f7c230..dbfe02429 100644
+--- a/src/udev/udev-builtin-hwdb.c
++++ b/src/udev/udev-builtin-hwdb.c
+@@ -27,6 +27,7 @@
+ 
+ #include "alloc-util.h"
+ #include "hwdb-util.h"
++#include "parse-util.h"
+ #include "string-util.h"
+ #include "udev-util.h"
+ #include "udev.h"
+@@ -63,7 +64,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev,
+ 
+ static const char *modalias_usb(struct udev_device *dev, char *s, size_t size) {
+         const char *v, *p;
+-        int vn, pn;
++        uint16_t vn, pn;
+ 
+         v = udev_device_get_sysattr_value(dev, "idVendor");
+         if (!v)
+@@ -71,12 +72,10 @@ static const char *modalias_usb(struct udev_device *dev, char *s, size_t size) {
+         p = udev_device_get_sysattr_value(dev, "idProduct");
+         if (!p)
+                 return NULL;
+-        vn = strtol(v, NULL, 16);
+-        if (vn <= 0)
+-                return NULL;
+-        pn = strtol(p, NULL, 16);
+-        if (pn <= 0)
+-                return NULL;
++        if (safe_atoux16(v, &vn) < 0)
++		return NULL;
++        if (safe_atoux16(p, &pn) < 0)
++		return NULL;
+         snprintf(s, size, "usb:v%04Xp%04X*", vn, pn);
+         return s;
+ }
+-- 
+2.17.0
+
diff --git a/meta/recipes-core/systemd/systemd_237.bb b/meta/recipes-core/systemd/systemd_237.bb
index b7c2113255..c4743a6b9d 100644
--- a/meta/recipes-core/systemd/systemd_237.bb
+++ b/meta/recipes-core/systemd/systemd_237.bb
@@ -52,6 +52,7 @@  SRC_URI += "file://touchscreen.rules \
            file://0032-memfd.patch \
            file://0033-basic-macros-rename-noreturn-into-_noreturn_-8456.patch \
            file://libmount.patch \
+           file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \
            "
 SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"