Page MenuHomeFreeBSD

stdin handling for ministat
Needs ReviewPublic

Authored by mp39590_gmail.com on Nov 10 2022, 5:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, May 4, 8:49 PM
Unknown Object (File)
Thu, Apr 24, 6:53 AM
Unknown Object (File)
Mon, Apr 14, 6:43 AM
Unknown Object (File)
Sun, Apr 13, 1:16 PM
Unknown Object (File)
Mar 21 2025, 9:31 PM
Unknown Object (File)
Mar 9 2025, 7:56 AM
Unknown Object (File)
Feb 27 2025, 8:12 AM
Unknown Object (File)
Feb 27 2025, 3:26 AM

Details

Reviewers
phk
Summary

Currently ministat doesn't handle such use case:

[freefall ~w/freebsd/usr.bin/ministat (main)] ./ministat iguana - < chameleon
ministat: Cannot open -: No error: 0

Also, while porting to OpenBSD it was noted that handling of 'ministat - -' is also broken:

643                 for (i = 0; i < nds; i++) {
644                         setfilenames[i] = argv[i];
645                         if (!strcmp(argv[i], "-"))
646                                 setfiles[0] = stdin;
647                         else
648                                 setfiles[i] = fopen(argv[i], "r");
649                         if (setfiles[i] == NULL)
650                                 err(2, "Cannot open %s", argv[i]);
651                 }

on line 645 we check for '-' and if it matches we set setfiles[0] to stdin, in case of 'ministat - -' we don't set new element, and check setfiles[1] for NULL, and fail, on OpenBSD it leads to a crash, since array is un-initialized.

Proposed patch fixes these two cases. Author is Ross L Richardson <openbsd@rlr.id.au>.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Hi,

The patch does the right thing. However, there is still a discrepancy how ministat(1) works with stdin. With the patch:

$ ministat - - <q
Dataset - must contain at least 3 data points

The reason is rather obvious -- it cannot rewind stdin to the initial position.

I agree though that this is a different issue and probably should be addressed separately.