Skip to content

xsprintf revert#4546

Merged
poettering merged 4 commits intosystemd:masterfrom
keszybz:xsprintf-revert
Nov 3, 2016
Merged

xsprintf revert#4546
poettering merged 4 commits intosystemd:masterfrom
keszybz:xsprintf-revert

Conversation

@keszybz
Copy link
Member

@keszybz keszybz commented Nov 3, 2016

No description provided.

This reverts some changes introduced in d054f0a.
xsprintf should be used in cases where we calculated the right buffer
size by hand (using DECIMAL_STRING_MAX and such), and never in cases where
we are printing externally specified strings of arbitrary length.

Fixes systemd#4534.
If we encounter the (unlikely) situation where the combined path to the
new root and a path to a mount to be moved together exceed maximum path length,
we shouldn't crash, but fail this path instead.
@keszybz keszybz added this to the v232 milestone Nov 3, 2016
@poettering poettering merged commit b23f2b7 into systemd:master Nov 3, 2016
else {
xsprintf(m->sender_buffer, ":1.%llu",
(unsigned long long)k->src_id);
xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produces:

src/libsystemd/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’:
src/libsystemd/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
                 xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
                                            ^
./src/basic/macro.h:45:44: note: in definition of macro ‘_unlikely_’
 #define _unlikely_(x) (__builtin_expect(!!(x),0))
                                            ^
./src/basic/stdio-util.h:30:9: note: in expansion of macro ‘assert_message_se’
         assert_message_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf), "xsprintf: " #buf "[] must be big enough")
         ^~~~~~~~~~~~~~~~~
src/libsystemd/sd-bus/bus-kernel.c:851:17: note: in expansion of macro ‘xsprintf’
                 xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
                 ^~~~~~~~
src/libsystemd/sd-bus/bus-kernel.c:862:49: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
                 xsprintf(m->destination_buffer, ":1.%"PRIu64, k->dst_id);
                                                 ^
./src/basic/macro.h:45:44: note: in definition of macro ‘_unlikely_’
 #define _unlikely_(x) (__builtin_expect(!!(x),0))
                                            ^
./src/basic/stdio-util.h:30:9: note: in expansion of macro ‘assert_message_se’
         assert_message_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf), "xsprintf: " #buf "[] must be big enough")
         ^~~~~~~~~~~~~~~~~
src/libsystemd/sd-bus/bus-kernel.c:862:17: note: in expansion of macro ‘xsprintf’
                 xsprintf(m->destination_buffer, ":1.%"PRIu64, k->dst_id);
                 ^~~~~~~~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, __u64 is defined differently than uint64_t. Kernel hackers FTW!

keszybz added a commit to keszybz/systemd that referenced this pull request Nov 3, 2016
This reverts commit 75ead2b.

Follow up for systemd#4546:
> @@ -848,8 +848,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         if (k->src_id == KDBUS_SRC_ID_KERNEL)
                 bus_message_set_sender_driver(bus, m);
         else {
-                xsprintf(m->sender_buffer, ":1.%llu",
-                         (unsigned long long)k->src_id);
+                xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);

This produces:
```
src/libsystemd/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’:
src/libsystemd/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long
unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
                 xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
                                            ^
@keszybz
Copy link
Member Author

keszybz commented Nov 3, 2016

I'd argue that this is a gcc bug: it's trying to be helpful but just gets in the way. It should never emit this warning when the variable is of the right size.

@keszybz keszybz deleted the xsprintf-revert branch November 3, 2016 13:28
keszybz added a commit that referenced this pull request Nov 3, 2016
This reverts commit 75ead2b.

Follow up for #4546:
> @@ -848,8 +848,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         if (k->src_id == KDBUS_SRC_ID_KERNEL)
                 bus_message_set_sender_driver(bus, m);
         else {
-                xsprintf(m->sender_buffer, ":1.%llu",
-                         (unsigned long long)k->src_id);
+                xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);

This produces:

src/libsystemd/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’:
src/libsystemd/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long
unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
                 xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
                                            ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants