Page MenuHomeFreeBSD

stdin handling for ministat
Needs ReviewPublic

Authored by mp39590_gmail.com on Nov 10 2022, 5:25 PM.
Tags
None
Referenced Files
F102473984: D37346.diff
Tue, Nov 12, 7:24 PM
Unknown Object (File)
Tue, Oct 22, 10:31 AM
Unknown Object (File)
Tue, Oct 22, 10:11 AM
Unknown Object (File)
Tue, Oct 22, 6:24 AM
Unknown Object (File)
Mon, Oct 21, 11:22 PM
Unknown Object (File)
Oct 4 2024, 11:12 AM
Unknown Object (File)
Oct 2 2024, 11:49 PM
Unknown Object (File)
Oct 2 2024, 9:02 PM

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.