]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkid: move error checks before JSON output initialization
authorKarel Zak <kzak@redhat.com>
Tue, 17 Feb 2026 10:09:09 +0000 (11:09 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 17 Feb 2026 10:09:09 +0000 (11:09 +0100)
Move the lowprobe and lookup error checks (missing device and missing
search type) before the JSON writer initialization. This prevents
partial JSON output being written to stdout before errx() terminates
the program.

Addresses: https://github.com/util-linux/util-linux/pull/4036
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/blkid.c

index 8d9148985fb1d7ecdbae95f1b305415d9cd16462..8c1f4fc616f132ef897d2dfd99a70caa2653aa3d 100644 (file)
@@ -914,6 +914,16 @@ int main(int argc, char **argv)
                pretty_print_dev(NULL);
        }
 
+       if (ctl.lowprobe && !numdev)
+               errx(BLKID_EXIT_OTHER,
+                    _("The low-level probing mode "
+                      "requires a device"));
+
+       if (ctl.lookup && !search_type)
+               errx(BLKID_EXIT_OTHER,
+                    _("The lookup option requires a "
+                      "search type specified using -t"));
+
        if (!ctl.eval && ctl.output & OUTPUT_JSON) {
                ul_jsonwrt_init(ctl.json_fmt, stdout, 0);
                ul_jsonwrt_root_open(ctl.json_fmt);
@@ -926,11 +936,6 @@ int main(int argc, char **argv)
                 */
                blkid_probe pr;
 
-               if (!numdev)
-                       errx(BLKID_EXIT_OTHER,
-                            _("The low-level probing mode "
-                              "requires a device"));
-
                /* automatically enable 'export' format for I/O Limits */
                if (!ctl.output  && ctl.lowprobe_topology)
                        ctl.output = OUTPUT_EXPORT_LIST;
@@ -988,10 +993,6 @@ int main(int argc, char **argv)
                 */
                blkid_dev dev;
 
-               if (!search_type)
-                       errx(BLKID_EXIT_OTHER,
-                            _("The lookup option requires a "
-                              "search type specified using -t"));
                /* Load any additional devices not in the cache */
                for (i = 0; i < numdev; i++)
                        blkid_get_dev(cache, devices[i], BLKID_DEV_NORMAL);