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)
Fri, May 24, 2:33 PM
Unknown Object (File)
Thu, May 16, 8:19 AM
Unknown Object (File)
Apr 18 2024, 9:37 AM
Unknown Object (File)
Apr 18 2024, 9:37 AM
Unknown Object (File)
Apr 18 2024, 9:09 AM
Unknown Object (File)
Apr 10 2024, 2:04 AM
Unknown Object (File)
Feb 23 2024, 9:50 AM
Unknown Object (File)
Feb 1 2024, 9:33 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.