Bug 267684 - ministat segmentation fault
Summary: ministat segmentation fault
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL: https://github.com/freebsd/freebsd-sr...
Keywords: crash
Depends on:
Blocks:
 
Reported: 2022-11-10 05:37 UTC by keen.sand4331
Modified: 2022-11-11 05:53 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description keen.sand4331 2022-11-10 05:37:33 UTC
[Noticed in the OpenBSD port.]

$ printf "0\n0\n0\n" | ministat - -
Segmentation fault (core dumped)

The problem is [in ministat.c] at line 646:
		nds = argc;
		for (i = 0; i < nds; i++) {
			setfilenames[i] = argv[i];
			if (!strcmp(argv[i], "-"))
---->				setfiles[0] = stdin;
			else
				setfiles[i] = fopen(argv[i], "r");
			if (setfiles[i] == NULL)
				err(2, "Cannot open %s", argv[i]);
		}

The simplest fix is just to change that to:
				setfiles[i] = stdin;

With that in place, ministat will error out reporting that
(on second reading) the input has fewer than 3 data points.
Comment 1 keen.sand4331 2022-11-10 08:46:23 UTC
Just to be clear: the issue is seen any time "-" is used
as other than first data source.
Comment 2 mp39590 2022-11-10 19:05:19 UTC
DiffRev for this patch is here: https://reviews.freebsd.org/D37346