[Bug 267684] ministat segmentation fault

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 10 Nov 2022 05:37:33 UTC

            Bug ID: 267684
           Summary: ministat segmentation fault
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: keen.sand4331@fastmail.com

[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;
                                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.

You are receiving this mail because:
You are the assignee for the bug.