]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #19226 from keszybz/reenable-maybe-unitialized-warning
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 8 Apr 2021 18:29:05 +0000 (20:29 +0200)
committerGitHub <noreply@github.com>
Thu, 8 Apr 2021 18:29:05 +0000 (20:29 +0200)
meson: re-enable -Wmaybe-uninitialized

22 files changed:
docs/COREDUMP_PACKAGE_METADATA.md
man/sd_bus_is_open.xml
man/systemd-coredump.xml
man/systemd-cryptenroll.xml
mkosi.build
src/basic/path-util.c
src/basic/path-util.h
src/basic/proc-cmdline.c
src/core/execute.c
src/coredump/coredump.c
src/coredump/coredumpctl.c
src/coredump/stacktrace.c
src/libsystemd/sd-bus/sd-bus.c
src/network/networkd-dhcp-common.c
src/network/networkd-link-bus.c
src/network/networkd-manager-bus.c
src/network/networkd-manager.c
src/test/test-firewall-util.c
src/test/test-path-util.c
src/udev/udev-builtin-net_id.c
test/fuzz/fuzz-unit-file/oss-fuzz-32991 [new file with mode: 0644]
test/units/testsuite-50.sh

index 54ff31ee78f08d89ba9abd88dbba58b8db9caa8c..bf7588f43a1d2b4c52ad425298c76b9faa407400 100644 (file)
@@ -52,12 +52,12 @@ Value: a JSON string with the structure described below
 
 ```json
 {
-     "packageType":"rpm",          # this provides a namespace for the package+package-version fields
-     "packageDistro":"fedora",
-     "packageDistroVersion":"33",
-     "package":"coreutils",
-     "packageVersion": "4711.0815.fc13.arm32",
-     "cpe":                        # A CPE name for the operating system, `CPE_NAME` from os-release is a good default
+     "type":"rpm",          # this provides a namespace for the package+package-version fields
+     "os":"fedora",
+     "osVersion":"33",
+     "name":"coreutils",
+     "version": "4711.0815.fc13.arm32",
+     "osCpe":               # A CPE name for the operating system, `CPE_NAME` from os-release is a good default
 }
 ```
 
@@ -72,38 +72,34 @@ SECTIONS
 {
     .note.package : ALIGN(4) {
         BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */
-        BYTE(0x73) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */
+        BYTE(0x64) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */
         BYTE(0x7e) BYTE(0x1a) BYTE(0xfe) BYTE(0xca) /* Note ID */
         BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */
-        BYTE(0x7b) BYTE(0x22) BYTE(0x70) BYTE(0x61) /* Value: '{"packageType":"rpm","package":"systemd","packageVersion":"248~rc2-1.fc34","cpe":"cpe:/o:fedoraproject:fedora:33"}\x00\x00' */
-        BYTE(0x63) BYTE(0x6b) BYTE(0x61) BYTE(0x67)
-        BYTE(0x65) BYTE(0x54) BYTE(0x79) BYTE(0x70)
-        BYTE(0x65) BYTE(0x22) BYTE(0x3a) BYTE(0x22)
-        BYTE(0x72) BYTE(0x70) BYTE(0x6d) BYTE(0x22)
-        BYTE(0x2c) BYTE(0x22) BYTE(0x70) BYTE(0x61)
-        BYTE(0x63) BYTE(0x6b) BYTE(0x61) BYTE(0x67)
-        BYTE(0x65) BYTE(0x22) BYTE(0x3a) BYTE(0x22)
-        BYTE(0x73) BYTE(0x79) BYTE(0x73) BYTE(0x74)
-        BYTE(0x65) BYTE(0x6d) BYTE(0x64) BYTE(0x22)
-        BYTE(0x2c) BYTE(0x22) BYTE(0x70) BYTE(0x61)
-        BYTE(0x63) BYTE(0x6b) BYTE(0x61) BYTE(0x67)
-        BYTE(0x65) BYTE(0x56) BYTE(0x65) BYTE(0x72)
-        BYTE(0x73) BYTE(0x69) BYTE(0x6f) BYTE(0x6e)
-        BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x32)
-        BYTE(0x34) BYTE(0x38) BYTE(0x7e) BYTE(0x72)
-        BYTE(0x63) BYTE(0x32) BYTE(0x2d) BYTE(0x31)
-        BYTE(0x2e) BYTE(0x66) BYTE(0x63) BYTE(0x33)
-        BYTE(0x34) BYTE(0x22) BYTE(0x2c) BYTE(0x22)
-        BYTE(0x63) BYTE(0x70) BYTE(0x65) BYTE(0x22)
-        BYTE(0x3a) BYTE(0x22) BYTE(0x63) BYTE(0x70)
-        BYTE(0x65) BYTE(0x3a) BYTE(0x2f) BYTE(0x6f)
-        BYTE(0x3a) BYTE(0x66) BYTE(0x65) BYTE(0x64)
-        BYTE(0x6f) BYTE(0x72) BYTE(0x61) BYTE(0x70)
-        BYTE(0x72) BYTE(0x6f) BYTE(0x6a) BYTE(0x65)
-        BYTE(0x63) BYTE(0x74) BYTE(0x3a) BYTE(0x66)
-        BYTE(0x65) BYTE(0x64) BYTE(0x6f) BYTE(0x72)
-        BYTE(0x61) BYTE(0x3a) BYTE(0x33) BYTE(0x33)
-        BYTE(0x22) BYTE(0x7d) BYTE(0x00) BYTE(0x00)
+        BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","name":"systemd","version":"248~rc2-1.fc34","osCpe":"cpe:/o:fedoraproject:fedora:33"}\x00' */
+        BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a)
+        BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d)
+        BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6e)
+        BYTE(0x61) BYTE(0x6d) BYTE(0x65) BYTE(0x22)
+        BYTE(0x3a) BYTE(0x22) BYTE(0x73) BYTE(0x79)
+        BYTE(0x73) BYTE(0x74) BYTE(0x65) BYTE(0x6d)
+        BYTE(0x64) BYTE(0x22) BYTE(0x2c) BYTE(0x22)
+        BYTE(0x76) BYTE(0x65) BYTE(0x72) BYTE(0x73)
+        BYTE(0x69) BYTE(0x6f) BYTE(0x6e) BYTE(0x22)
+        BYTE(0x3a) BYTE(0x22) BYTE(0x32) BYTE(0x34)
+        BYTE(0x38) BYTE(0x7e) BYTE(0x72) BYTE(0x63)
+        BYTE(0x32) BYTE(0x2d) BYTE(0x31) BYTE(0x2e)
+        BYTE(0x66) BYTE(0x63) BYTE(0x33) BYTE(0x34)
+        BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f)
+        BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65)
+        BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x63)
+        BYTE(0x70) BYTE(0x65) BYTE(0x3a) BYTE(0x2f)
+        BYTE(0x6f) BYTE(0x3a) BYTE(0x66) BYTE(0x65)
+        BYTE(0x64) BYTE(0x6f) BYTE(0x72) BYTE(0x61)
+        BYTE(0x70) BYTE(0x72) BYTE(0x6f) BYTE(0x6a)
+        BYTE(0x65) BYTE(0x63) BYTE(0x74) BYTE(0x3a)
+        BYTE(0x66) BYTE(0x65) BYTE(0x64) BYTE(0x6f)
+        BYTE(0x72) BYTE(0x61) BYTE(0x3a) BYTE(0x33)
+        BYTE(0x33) BYTE(0x22) BYTE(0x7d) BYTE(0x00)
     }
 }
 INSERT AFTER .note.gnu.build-id;
index 8e0aed29b3319c6768a1d99f703507215cb6eecd..621ed272bb8eba1b990f4f28551c58b90d4d29f1 100644 (file)
@@ -57,6 +57,9 @@
     zero outside of this state, and positive otherwise. Effectively, this function returns positive while regular
     messages can be sent or received on the connection.</para>
 
+    <para>The <parameter>bus</parameter> argument may be <constant>NULL</constant>, zero is also returned in
+    that case.</para>
+
     <para>To be notified when the connection is fully established, use
     <citerefentry><refentrytitle>sd_bus_set_connected_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry> and
     install a match for the <function>Connected()</function> signal on the
@@ -68,8 +71,8 @@
   <refsect1>
     <title>Return Value</title>
 
-    <para>On success, these functions return 0 or a positive integer. On failure, they return a negative errno-style
-    error code.</para>
+    <para>Those functions return 0 if the bus is <emphasis>not</emphasis> in the given state, and a positive
+    integer when it is. On failure, a negative errno-style error code is returned.</para>
 
     <refsect2>
       <title>Errors</title>
index d994a21d9b5bef33d09cad3deafb08ed9170202b..707905f1ba922952823936ef4d2b7aa50453dd74 100644 (file)
@@ -353,9 +353,9 @@ flags:   ...
       </varlistentry>
 
       <varlistentry>
-        <term><varname>COREDUMP_PKGMETA_PACKAGE=</varname></term>
-        <term><varname>COREDUMP_PKGMETA_PACKAGEVERSION=</varname></term>
-        <term><varname>COREDUMP_PKGMETA_JSON=</varname></term>
+        <term><varname>COREDUMP_PACKAGE_NAME=</varname></term>
+        <term><varname>COREDUMP_PACKAGE_VERSION=</varname></term>
+        <term><varname>COREDUMP_PACKAGE_JSON=</varname></term>
 
         <listitem><para>If the executable contained .package metadata ELF notes, they will be
         parsed and attached. The <varname>package</varname> and <varname>packageVersion</varname>
index 93acdd02a5bfbc35b19a9d21e629614466d52c15..9751444e50860353c0307ff612da81f0abff9afb 100644 (file)
 
               <row>
                 <entry>8</entry>
-                <entry><citerefentry><refentrytitle>sd-boot</refentrytitle><manvolnum>8</manvolnum></citerefentry> measures the kernel command line in this PCR.</entry>
+                <entry><citerefentry><refentrytitle>sd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry> measures the kernel command line in this PCR.</entry>
               </row>
             </tbody>
           </tgroup>
index a74fc196be5b3630536b8cf7b01f38c087ac5c95..ff339b440c29f1950878dd02dcbd3fc146241f36 100755 (executable)
@@ -14,6 +14,18 @@ if ! mountpoint -q "$SRCDIR"; then
         umask 022
 fi
 
+# On Fedora "ld" is (unfortunately — if you ask me) managed via
+# "alternatives". Since we'd like to support building images in environments
+# with only /usr/ around (e.g. mkosi's UsrOnly=1 option), we have the problem
+# that /usr/bin/ld is a symlink that points to a non-existing file in
+# /etc/alternative/ in this mode. Let's work around this for now by manually
+# redirect "ld" to "ld.bfd", i.e. circumventing the /usr/bin/ld symlink.
+if [ ! -x /usr/bin/ld -a -x /usr/bin/ld.bfd ] ; then
+        mkdir -p "$HOME"/bin
+        ln -s /usr/bin/ld.bfd "$HOME"/bin/ld
+        PATH="$HOME/bin:$PATH"
+fi
+
 # If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it
 # as out-of-tree build dir. Otherwise, let's make up our own builddir.
 [ -z "$BUILDDIR" ] && BUILDDIR=build
index f40f3f27e96c862c64bdf1dfd0736404c39f553c..f98859939cddad1994d4a73504bbfcb8dcf9edb2 100644 (file)
@@ -527,6 +527,27 @@ bool path_equal_or_files_same(const char *a, const char *b, int flags) {
         return path_equal(a, b) || files_same(a, b, flags) > 0;
 }
 
+bool path_equal_filename(const char *a, const char *b) {
+        _cleanup_free_ char *a_basename = NULL, *b_basename = NULL;
+        int r;
+
+        assert(a);
+        assert(b);
+
+        r = path_extract_filename(a, &a_basename);
+        if (r < 0) {
+                log_debug_errno(r, "Failed to parse basename of %s: %m", a);
+                return false;
+        }
+        r = path_extract_filename(b, &b_basename);
+        if (r < 0) {
+                log_debug_errno(r, "Failed to parse basename of %s: %m", b);
+                return false;
+        }
+
+        return path_equal(a_basename, b_basename);
+}
+
 char* path_join_internal(const char *first, ...) {
         char *joined, *q;
         const char *p;
index c0746f68d7aea12331861700c5c5109751c7d906..f82d935dc5c739d8d76afae6cbcaf6fee61ba568 100644 (file)
@@ -61,6 +61,8 @@ char* path_startswith(const char *path, const char *prefix) _pure_;
 int path_compare(const char *a, const char *b) _pure_;
 bool path_equal(const char *a, const char *b) _pure_;
 bool path_equal_or_files_same(const char *a, const char *b, int flags);
+/* Compares only the last portion of the input paths, ie: the filenames */
+bool path_equal_filename(const char *a, const char *b);
 char* path_join_internal(const char *first, ...);
 #define path_join(x, ...) path_join_internal(x, __VA_ARGS__, POINTER_MAX)
 
index 0b6fb137bdc304e3921aed759b56a4871d6e92f6..410b8a3eb5de67e7d1defd0a5377bf8441520102 100644 (file)
@@ -47,7 +47,7 @@ static int proc_cmdline_extract_first(const char **p, char **ret_word, ProcCmdli
                 _cleanup_free_ char *word = NULL;
                 const char *c;
 
-                r = extract_first_word(&q, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RELAX);
+                r = extract_first_word(&q, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RELAX|EXTRACT_RETAIN_ESCAPE);
                 if (r < 0)
                         return r;
                 if (r == 0)
index 2152fa8500077021eb7fe879a826fc6390eb0268..4d6b75e8458b8d95fafdd6f7064c61f3b621ab22 100644 (file)
@@ -4916,6 +4916,7 @@ void exec_context_done(ExecContext *c) {
         c->stdin_data_size = 0;
 
         c->network_namespace_path = mfree(c->network_namespace_path);
+        c->ipc_namespace_path = mfree(c->ipc_namespace_path);
 
         c->log_namespace = mfree(c->log_namespace);
 
index be813f57f19ae78743103e05644286cdbe04f9fc..b6cc7e3887f97497911a176ba1ab9790caf84748 100644 (file)
@@ -792,56 +792,23 @@ log:
                 if (r < 0)
                         return log_error_errno(r, "Failed to format JSON package metadata: %m");
 
-                (void) iovw_put_string_field(iovw, "COREDUMP_PKGMETA_JSON=", formatted_json);
+                (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_JSON=", formatted_json);
         }
 
         JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, json_metadata) {
-                _cleanup_free_ char *module_basename = NULL, *exe_basename = NULL;
-                const char *key;
-                JsonVariant *w;
-
-                /* The module name, most likely parsed from the ELF core file,
-                 * sometimes contains the full path and sometimes does not. */
-                r = path_extract_filename(module_name, &module_basename);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to parse module basename: %m");
-                r = path_extract_filename(context->meta[META_EXE], &exe_basename);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to parse executable basename: %m");
+                JsonVariant *package_name, *package_version;
 
                 /* We only add structured fields for the 'main' ELF module */
-                if (!streq(module_basename, exe_basename))
+                if (!path_equal_filename(module_name, context->meta[META_EXE]))
                         continue;
 
-                /* Cannot nest two JSON_VARIANT_OBJECT_FOREACH as they define the same
-                 * iterator variable '_state' */
-                for (struct json_variant_foreach_state _state2 = { (module_json), 0 };     \
-                     json_variant_is_object(_state2.variant) &&                  \
-                             _state2.idx < json_variant_elements(_state2.variant) && \
-                             ({ key = json_variant_string(json_variant_by_index(_state2.variant, _state2.idx)); \
-                                       w = json_variant_by_index(_state2.variant, _state2.idx + 1); \
-                                       true; });                                  \
-                     _state2.idx += 2) {
-                        _cleanup_free_ char *metadata_id = NULL, *key_upper = NULL;
-
-                        if (!json_variant_is_string(w))
-                                continue;
-
-                        if (!STR_IN_SET(key, "package", "packageVersion"))
-                                continue;
+                package_name = json_variant_by_key(module_json, "name");
+                if (package_name)
+                        (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_NAME=", json_variant_string(package_name));
 
-                        /* Journal metadata field names need to be upper case */
-                        key_upper = strdup(key);
-                        if (!key_upper)
-                                return log_oom();
-                        key_upper = ascii_strupper(key_upper);
-
-                        metadata_id = strjoin("COREDUMP_PKGMETA_", key_upper, "=");
-                        if (!metadata_id)
-                                return log_oom();
-
-                        (void) iovw_put_string_field(iovw, metadata_id, json_variant_string(w));
-                }
+                package_version = json_variant_by_key(module_json, "version");
+                if (package_version)
+                        (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_VERSION=", json_variant_string(package_version));
         }
 
         /* Optionally store the entire coredump in the journal */
index 3418753a31b3312d09108ba5eec01835f19cb74b..02bad966c1cc7dd96bffc231889cd6f9d89c4003 100644 (file)
@@ -575,9 +575,9 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
                 RETRIEVE(d, l, "COREDUMP_FILENAME", filename);
                 RETRIEVE(d, l, "COREDUMP_TRUNCATED", truncated);
                 RETRIEVE(d, l, "COREDUMP", coredump);
-                RETRIEVE(d, l, "COREDUMP_PKGMETA_PACKAGE", pkgmeta_name);
-                RETRIEVE(d, l, "COREDUMP_PKGMETA_PACKAGEVERSION", pkgmeta_version);
-                RETRIEVE(d, l, "COREDUMP_PKGMETA_JSON", pkgmeta_json);
+                RETRIEVE(d, l, "COREDUMP_PACKAGE_NAME", pkgmeta_name);
+                RETRIEVE(d, l, "COREDUMP_PACKAGE_VERSION", pkgmeta_version);
+                RETRIEVE(d, l, "COREDUMP_PACKAGE_JSON", pkgmeta_json);
                 RETRIEVE(d, l, "_BOOT_ID", boot_id);
                 RETRIEVE(d, l, "_MACHINE_ID", machine_id);
                 RETRIEVE(d, l, "MESSAGE", message);
@@ -729,53 +729,22 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
                 _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
 
                 r = json_parse(pkgmeta_json, 0, &v, NULL, NULL);
-                if (r < 0) {
+                if (r < 0)
                         log_warning_errno(r, "json_parse on %s failed, ignoring: %m", pkgmeta_json);
-                else {
+                else {
                         const char *module_name;
                         JsonVariant *module_json;
 
-                        /* Cannot nest two JSON_VARIANT_OBJECT_FOREACH as they define the same
-                        * iterator variable '_state' */
-                        for (struct json_variant_foreach_state _state2 = { (v), 0 };     \
-                             json_variant_is_object(_state2.variant) &&                  \
-                                     _state2.idx < json_variant_elements(_state2.variant) && \
-                                     ({ module_name = json_variant_string(json_variant_by_index(_state2.variant, _state2.idx)); \
-                                        module_json = json_variant_by_index(_state2.variant, _state2.idx + 1); \
-                                        true; });                                  \
-                             _state2.idx += 2) {
-                                _cleanup_free_ char *module_basename = NULL, *exe_basename = NULL;
-                                const char *key;
-                                JsonVariant *w;
-
-                                /* The module name, most likely parsed from the ELF core file,
-                                 * sometimes contains the full path and sometimes does not. */
-                                r = path_extract_filename(module_name, &module_basename);
-                                if (r < 0) {
-                                        log_warning_errno(r, "Failed to parse module basename: %m");
-                                        break;
-                                }
-                                r = path_extract_filename(exe, &exe_basename);
-                                if (r < 0) {
-                                        log_warning_errno(r, "Failed to parse executable basename: %m");
-                                        break;
-                                }
+                        JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, v) {
+                                JsonVariant *build_id;
 
                                 /* We only print the build-id for the 'main' ELF module */
-                                if (!streq(module_basename, exe_basename))
+                                if (!path_equal_filename(module_name, exe))
                                         continue;
 
-                                JSON_VARIANT_OBJECT_FOREACH(key, w, module_json) {
-                                        if (!json_variant_is_string(w))
-                                                continue;
-
-                                        if (!streq(key, "buildid"))
-                                                continue;
-
-                                        fprintf(file, "      build-id: %s\n", json_variant_string(w));
-
-                                        break;
-                                }
+                                build_id = json_variant_by_key(module_json, "buildId");
+                                if (build_id)
+                                        fprintf(file, "      build-id: %s\n", json_variant_string(build_id));
 
                                 break;
                         }
index c16f12f09b46c4175a9bbcc2f2eab6045b78c14d..102ad2e65beb51ec0f8ff402b49ecc1590fa4621 100644 (file)
@@ -166,7 +166,6 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e
                          * magic ID is always the same. */
                         if (note_header.n_type == ELF_PACKAGE_METADATA_ID) {
                                 _cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
-                                char *name_key = NULL;
 
                                 r = json_parse(payload, 0, &v, NULL, NULL);
                                 if (r < 0) {
@@ -182,7 +181,7 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e
                                 fputc('\n', c->f);
 
                                 /* Secondly, if we have a build-id, merge it in the same JSON object
-                                 * so that it apperas all nicely together in the logs/metadata. */
+                                 * so that it appears all nicely together in the logs/metadata. */
                                 if (id_json) {
                                         r = json_variant_merge(&v, id_json);
                                         if (r < 0) {
@@ -206,14 +205,9 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e
                                 }
 
                                 /* Finally stash the name, so we avoid double visits. */
-                                name_key = strdup(name);
-                                if (!name_key) {
-                                        log_oom();
-                                        return DWARF_CB_ABORT;
-                                }
-                                r = set_ensure_consume(c->modules, &string_hash_ops, name_key);
+                                r = set_put_strdup(c->modules, name);
                                 if (r < 0) {
-                                        log_error_errno(r, "set_ensure_consume failed: %m");
+                                        log_error_errno(r, "set_put_strdup failed: %m");
                                         return DWARF_CB_ABORT;
                                 }
 
@@ -247,35 +241,26 @@ static int module_callback(Dwfl_Module *mod, void **userdata, const char *name,
          * The build-id is easy, as libdwfl parses it during the dwfl_core_file_report() call and
          * stores it separately in an internal library struct. */
         id_len = dwfl_module_build_id(mod, &id, &id_vaddr);
-        if (id_len <= 0) {
+        if (id_len <= 0)
                 /* If we don't find a build-id, note it in the journal message, and try
                  * anyway to find the package metadata. It's unlikely to have the latter
                  * without the former, but there's no hard rule. */
-                fprintf(c->f, "Found module %s without build-id\n", name);
-        } else {
-                _cleanup_free_ char *id_hex = NULL, *id_hex_prefixed = NULL;
-
-                id_hex = hexmem(id, id_len);
-                if (!id_hex) {
-                        log_oom();
-                        return DWARF_CB_ABORT;
-                }
-
-                fprintf(c->f, "Found module %s with build-id: %s\n", name, id_hex);
+                fprintf(c->f, "Found module %s without build-id.\n", name);
+        else {
+                JsonVariant *build_id;
 
                 /* We will later parse package metadata json and pass it to our caller. Prepare the
                 * build-id in json format too, so that it can be appended and parsed cleanly. It
                 * will then be added as metadata to the journal message with the stack trace. */
-                id_hex_prefixed = strjoin("{\"buildid\":\"", id_hex, "\"}");
-                if (!id_hex_prefixed) {
-                        log_oom();
-                        return DWARF_CB_ABORT;
-                }
-                r = json_parse(id_hex_prefixed, 0, &id_json, NULL, NULL);
+                r = json_build(&id_json, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("buildId", JSON_BUILD_HEX(id, id_len))));
                 if (r < 0) {
-                        log_error_errno(r, "json_parse on %s failed: %m", id_hex_prefixed);
+                        log_error_errno(r, "json_build on build-id failed: %m");
                         return DWARF_CB_ABORT;
                 }
+
+                build_id = json_variant_by_key(id_json, "buildId");
+                assert_se(build_id);
+                fprintf(c->f, "Found module %s with build-id: %s\n", name, json_variant_string(build_id));
         }
 
         /* The .note.package metadata is more difficult. From the module, we need to get a reference
index 1e3b34a40576d028335c0f93c310ed6de657ddd6..8bcf4f6c50630401d6b07a8bf2e3241575d9f5c6 100644 (file)
@@ -1800,7 +1800,9 @@ void bus_enter_closing(sd_bus *bus) {
 DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_bus, sd_bus, bus_free);
 
 _public_ int sd_bus_is_open(sd_bus *bus) {
-        assert_return(bus, -EINVAL);
+        if (!bus)
+                return 0;
+
         assert_return(bus = bus_resolve(bus), -ENOPKG);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
@@ -1808,7 +1810,9 @@ _public_ int sd_bus_is_open(sd_bus *bus) {
 }
 
 _public_ int sd_bus_is_ready(sd_bus *bus) {
-        assert_return(bus, -EINVAL);
+        if (!bus)
+                return 0;
+
         assert_return(bus = bus_resolve(bus), -ENOPKG);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
index 0de1892fc955bbdc97d662c3f4d99b3c2dc50469..9677dfb0c36b39e4998613f8b1153ea1c2453302 100644 (file)
@@ -167,7 +167,7 @@ int manager_request_product_uuid(Manager *m, Link *link) {
                         return log_oom();
         }
 
-        if (!m->bus || sd_bus_is_ready(m->bus) <= 0) {
+        if (sd_bus_is_ready(m->bus) <= 0) {
                 log_debug("Not connected to system bus, requesting product UUID later.");
                 return 0;
         }
index d303ff20221744faf24a112d95e5da4413b93880..16058c6fcf2649ccc2d5cfd13d489bcfcf6c01b1 100644 (file)
@@ -854,7 +854,7 @@ int link_send_changed_strv(Link *link, char **properties) {
         assert(link->manager);
         assert(properties);
 
-        if (!link->manager->bus)
+        if (sd_bus_is_ready(link->manager->bus) <= 0)
                 return 0;
 
         p = link_bus_path(link);
index fce10a7e7dcfaeb20f80713b093fec735c35fcf7..138d76541415a2d0fa8b73df34d455342421eb83 100644 (file)
@@ -339,7 +339,7 @@ int manager_send_changed_strv(Manager *manager, char **properties) {
         assert(manager);
         assert(properties);
 
-        if (!manager->bus)
+        if (sd_bus_is_ready(manager->bus) <= 0)
                 return 0;
 
         return sd_bus_emit_properties_changed_strv(
index bfdb1f8c96643574015257448cbcbb1ea7a453dd..a8db2cc44bb437458cab93c52670b39d1891c6ac 100644 (file)
@@ -767,8 +767,8 @@ int manager_set_hostname(Manager *m, const char *hostname) {
         if (r < 0)
                 return r;
 
-        if (!m->bus || sd_bus_is_ready(m->bus) <= 0) {
-                log_debug("Not connected to system bus, setting hostname later.");
+        if (sd_bus_is_ready(m->bus) <= 0) {
+                log_debug("Not connected to system bus, setting system hostname later.");
                 return 0;
         }
 
@@ -784,7 +784,6 @@ int manager_set_hostname(Manager *m, const char *hostname) {
                         "sb",
                         hostname,
                         false);
-
         if (r < 0)
                 return log_error_errno(r, "Could not set transient hostname: %m");
 
@@ -817,8 +816,8 @@ int manager_set_timezone(Manager *m, const char *tz) {
         if (r < 0)
                 return r;
 
-        if (!m->bus || sd_bus_is_ready(m->bus) <= 0) {
-                log_debug("Not connected to system bus, setting timezone later.");
+        if (sd_bus_is_ready(m->bus) <= 0) {
+                log_debug("Not connected to system bus, setting system timezone later.");
                 return 0;
         }
 
index c5a138ee1ecb19ef4ef4701b84cd99a104909de5..d2843cfab73da20a52234a7f98f53e327f9efad8 100644 (file)
@@ -61,6 +61,13 @@ static bool test_v4(FirewallContext *ctx) {
 
         log_info("/* %s(backend=%s) */", __func__, firewall_backend_to_string(ctx->backend));
 
+#if HAVE_LIBIPTC
+        if (ctx->backend == FW_BACKEND_IPTABLES && fw_iptables_init_nat(NULL) < 0) {
+                log_debug("iptables backend is used, but nat table is not enabled, skipping tests");
+                return false;
+        }
+#endif
+
         assert_se(fw_add_masquerade(&ctx, true, AF_INET, NULL, 0) == -EINVAL);
         assert_se(fw_add_masquerade(&ctx, true, AF_INET, parse_addr("10.1.2.0", &u), 0) == -EINVAL);
 
@@ -102,11 +109,6 @@ int main(int argc, char *argv[]) {
         if (ctx->backend == FW_BACKEND_NONE)
                 return EXIT_TEST_SKIP;
 
-#if HAVE_LIBIPTC
-        if (ctx->backend == FW_BACKEND_IPTABLES && fw_iptables_init_nat(NULL) < 0)
-                return EXIT_TEST_SKIP;
-#endif
-
         if (test_v4(ctx) && ctx->backend == FW_BACKEND_NFTABLES)
                 test_v6(ctx);
 
index b49b0ae9081691cdcfb559e1bdd32e4ad0d93c14..1572483602c38dfcf21074b1964213b90f954deb 100644 (file)
@@ -113,6 +113,11 @@ static void test_path(void) {
         assert_se(!path_equal_ptr("/a", "/b"));
         assert_se(!path_equal_ptr("/a", NULL));
         assert_se(!path_equal_ptr(NULL, "/a"));
+
+        assert_se(path_equal_filename("/a/c", "/b/c"));
+        assert_se(path_equal_filename("/a", "/a"));
+        assert_se(!path_equal_filename("/a/b", "/a/c"));
+        assert_se(!path_equal_filename("/b", "/c"));
 }
 
 static void test_path_equal_root(void) {
index 66c52e624cd8db9536a26e7bf1e4cfa307c20412..088bfe38d9ef23d72e8ac1aa61b53f3530d9b4e0 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/pci_regs.h>
 
 #include "alloc-util.h"
+#include "device-util.h"
 #include "dirent-util.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -262,18 +263,60 @@ static bool is_pci_bridge(sd_device *dev) {
         return strneq(p + 2, "04", 2);
 }
 
+static int parse_hotplug_slot_from_function_id(sd_device *dev, const char *slots, uint32_t *ret) {
+        uint64_t function_id;
+        char path[PATH_MAX];
+        const char *attr;
+        int r;
+
+        /* The <sysname>/function_id attribute is unique to the s390 PCI driver. If present, we know
+         * that the slot's directory name for this device is /sys/bus/pci/XXXXXXXX/ where XXXXXXXX is
+         * the fixed length 8 hexadecimal character string representation of function_id. Therefore we
+         * can short cut here and just check for the existence of the slot directory. As this directory
+         * has to exist, we're emitting a debug message for the unlikely case it's not found. Note that
+         * the domain part doesn't belong to the slot name here because there's a 1-to-1 relationship
+         * between PCI function and its hotplug slot. */
+
+        assert(dev);
+        assert(slots);
+        assert(ret);
+
+        if (!naming_scheme_has(NAMING_SLOT_FUNCTION_ID))
+                return 0;
+
+        if (sd_device_get_sysattr_value(dev, "function_id", &attr) < 0)
+                return 0;
+
+        r = safe_atou64(attr, &function_id);
+        if (r < 0)
+                return log_device_debug_errno(dev, r, "Failed to parse function_id, ignoring: %s", attr);
+
+        if (function_id <= 0 || function_id > UINT32_MAX)
+                return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
+                                              "Invalid function id (0x%"PRIx64"), ignoring.",
+                                              function_id);
+
+        if (!snprintf_ok(path, sizeof path, "%s/%08"PRIx64, slots, function_id))
+                return log_device_debug_errno(dev, SYNTHETIC_ERRNO(ENAMETOOLONG),
+                                              "PCI slot path is too long, ignoring.");
+
+        if (access(path, F_OK) < 0)
+                return log_device_debug_errno(dev, errno, "Cannot access %s, ignoring: %m", path);
+
+        *ret = (uint32_t) function_id;
+        return 1;
+}
+
 static int dev_pci_slot(sd_device *dev, struct netnames *names) {
-        unsigned long dev_port = 0;
-        unsigned domain, bus, slot, func;
-        int hotplug_slot = -1;
-        size_t l;
-        char *s;
         const char *sysname, *attr, *port_name = NULL, *syspath;
         _cleanup_(sd_device_unrefp) sd_device *pci = NULL;
-        sd_device *hotplug_slot_dev;
-        char slots[PATH_MAX];
         _cleanup_closedir_ DIR *dir = NULL;
-        struct dirent *dent;
+        unsigned domain, bus, slot, func;
+        sd_device *hotplug_slot_dev;
+        unsigned long dev_port = 0;
+        uint32_t hotplug_slot = 0;
+        char slots[PATH_MAX], *s;
+        size_t l;
         int r;
 
         r = sd_device_get_sysname(names->pcidev, &sysname);
@@ -342,44 +385,29 @@ static int dev_pci_slot(sd_device *dev, struct netnames *names) {
 
         hotplug_slot_dev = names->pcidev;
         while (hotplug_slot_dev) {
-                if (sd_device_get_sysname(hotplug_slot_dev, &sysname) < 0)
-                        continue;
+                struct dirent *dent;
 
-                /*  The <sysname>/function_id attribute is unique to the s390 PCI driver.
-                    If present, we know that the slot's directory name for this device is
-                    /sys/bus/pci/XXXXXXXX/ where XXXXXXXX is the fixed length 8 hexadecimal
-                    character string representation of function_id.
-                    Therefore we can short cut here and just check for the existence of
-                    the slot directory. As this directory has to exist, we're emitting a
-                    debug message for the unlikely case it's not found.
-                    Note that the domain part of doesn't belong to the slot name here
-                    because there's a 1-to-1 relationship between PCI function and its hotplug
-                    slot.
-                 */
-                if (naming_scheme_has(NAMING_SLOT_FUNCTION_ID) &&
-                    sd_device_get_sysattr_value(hotplug_slot_dev, "function_id", &attr) >= 0) {
-                        int function_id;
-                        _cleanup_free_ char *str;
-
-                        if (safe_atoi(attr, &function_id) >= 0 &&
-                            asprintf(&str, "%s/%08x/", slots, function_id) >= 0 &&
-                            access(str, R_OK) == 0) {
-                                hotplug_slot = function_id;
-                                domain = 0;
-                        } else
-                                log_debug("No matching slot for function_id (%s).", attr);
+                r = parse_hotplug_slot_from_function_id(hotplug_slot_dev, slots, &hotplug_slot);
+                if (r < 0)
+                        return 0;
+                if (r > 0) {
+                        domain = 0; /* See comments in parse_hotplug_slot_from_function_id(). */
                         break;
                 }
 
+                r = sd_device_get_sysname(hotplug_slot_dev, &sysname);
+                if (r < 0)
+                        return log_device_debug_errno(hotplug_slot_dev, r, "Failed to get sysname: %m");
+
                 FOREACH_DIRENT_ALL(dent, dir, break) {
-                        int i;
-                        char str[PATH_MAX];
                         _cleanup_free_ char *address = NULL;
+                        char str[PATH_MAX];
+                        uint32_t i;
 
                         if (dot_or_dot_dot(dent->d_name))
                                 continue;
 
-                        r = safe_atoi(dent->d_name, &i);
+                        r = safe_atou32(dent->d_name, &i);
                         if (r < 0 || i <= 0)
                                 continue;
 
@@ -394,12 +422,12 @@ static int dev_pci_slot(sd_device *dev, struct netnames *names) {
                                  * devices that will try to claim the same index and that would create name
                                  * collision. */
                                 if (naming_scheme_has(NAMING_BRIDGE_NO_SLOT) && is_pci_bridge(hotplug_slot_dev))
-                                        hotplug_slot = 0;
+                                        return 0;
 
                                 break;
                         }
                 }
-                if (hotplug_slot >= 0)
+                if (hotplug_slot > 0)
                         break;
                 if (sd_device_get_parent_with_subsystem_devtype(hotplug_slot_dev, "pci", NULL, &hotplug_slot_dev) < 0)
                         break;
@@ -411,7 +439,7 @@ static int dev_pci_slot(sd_device *dev, struct netnames *names) {
                 l = sizeof(names->pci_slot);
                 if (domain > 0)
                         l = strpcpyf(&s, l, "P%d", domain);
-                l = strpcpyf(&s, l, "s%d", hotplug_slot);
+                l = strpcpyf(&s, l, "s%"PRIu32, hotplug_slot);
                 if (func > 0 || is_pci_multifunction(names->pcidev))
                         l = strpcpyf(&s, l, "f%d", func);
                 if (port_name)
@@ -971,7 +999,7 @@ static int builtin_net_id(sd_device *dev, int argc, char *argv[], bool test) {
                         udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
 
                 if (names.pci_slot[0] &&
-                    snprintf(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.bcma_core))
+                    snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.bcma_core))
                         udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
                 return 0;
         }
diff --git a/test/fuzz/fuzz-unit-file/oss-fuzz-32991 b/test/fuzz/fuzz-unit-file/oss-fuzz-32991
new file mode 100644 (file)
index 0000000..6305b2a
Binary files /dev/null and b/test/fuzz/fuzz-unit-file/oss-fuzz-32991 differ
index e2d8ef6da23693b543f702ab7fba4220e5ccafa2..ae4e520ee0339e81cbe2c3fa3ba6ec264aa7b11e 100755 (executable)
@@ -32,13 +32,13 @@ os_release=$(test -e /etc/os-release && echo /etc/os-release || echo /usr/lib/os
 
 systemd-dissect --json=short ${image}.raw | grep -q -F '{"rw":"ro","designator":"root","partition_uuid":null,"partition_label":null,"fstype":"squashfs","architecture":null,"verity":"external"'
 systemd-dissect ${image}.raw | grep -q -F "MARKER=1"
-systemd-dissect ${image}.raw | grep -q -F -f $os_release
+systemd-dissect ${image}.raw | grep -q -F -f <(sed 's/"//g' $os_release)
 
 mv ${image}.verity ${image}.fooverity
 mv ${image}.roothash ${image}.foohash
 systemd-dissect --json=short ${image}.raw --root-hash=${roothash} --verity-data=${image}.fooverity | grep -q -F '{"rw":"ro","designator":"root","partition_uuid":null,"partition_label":null,"fstype":"squashfs","architecture":null,"verity":"external"'
 systemd-dissect ${image}.raw --root-hash=${roothash} --verity-data=${image}.fooverity | grep -q -F "MARKER=1"
-systemd-dissect ${image}.raw --root-hash=${roothash} --verity-data=${image}.fooverity | grep -q -F -f $os_release
+systemd-dissect ${image}.raw --root-hash=${roothash} --verity-data=${image}.fooverity | grep -q -F -f <(sed 's/"//g' $os_release)
 mv ${image}.fooverity ${image}.verity
 mv ${image}.foohash ${image}.roothash
 
@@ -130,7 +130,7 @@ VERITY_UUID=$(systemd-id128 -u show $(tail -c 32 ${image}.roothash) -u | tail -n
 systemd-dissect --json=short --root-hash ${roothash} ${image}.gpt | grep -q '{"rw":"ro","designator":"root","partition_uuid":"'$ROOT_UUID'","partition_label":"Root Partition","fstype":"squashfs","architecture":"'$architecture'","verity":"yes","node":'
 systemd-dissect --json=short --root-hash ${roothash} ${image}.gpt | grep -q '{"rw":"ro","designator":"root-verity","partition_uuid":"'$VERITY_UUID'","partition_label":"Verity Partition","fstype":"DM_verity_hash","architecture":"'$architecture'","verity":null,"node":'
 systemd-dissect --root-hash ${roothash} ${image}.gpt | grep -q -F "MARKER=1"
-systemd-dissect --root-hash ${roothash} ${image}.gpt | grep -q -F -f $os_release
+systemd-dissect --root-hash ${roothash} ${image}.gpt | grep -q -F -f <(sed 's/"//g' $os_release)
 
 systemd-dissect --root-hash ${roothash} --mount ${image}.gpt ${image_dir}/mount
 cat ${image_dir}/mount/usr/lib/os-release | grep -q -F -f $os_release