From: Karel Zak Date: Tue, 17 Feb 2026 10:09:09 +0000 (+0100) Subject: blkid: move error checks before JSON output initialization X-Git-Tag: v2.43-devel~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c13ec5273b2108ca38742879be5242f4beee7e5;p=thirdparty%2Futil-linux.git blkid: move error checks before JSON output initialization 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 --- diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index 8d9148985..8c1f4fc61 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -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);