Bug 198706 - [libstand] ngets shall exit on EOF
Summary: [libstand] ngets shall exit on EOF
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-03-19 14:14 UTC by Ivan Krivonos
Modified: 2019-01-21 10:07 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Krivonos 2015-03-19 14:14:44 UTC
Hi All,

I`ve noted that ngets() from libstand starts consuming CPU like mad when
EOF appears on stdin.  I see this issue with bhyveload when forwarding "user input" over pipe. Here is the simpliest program to reproduce:

cat > ./bget.c

#include 
#include 
#include 
#include

int main()
{
char str[512];

    for (;;) {
            ngets(str, sizeof(str));
            if (str[0] == '\n') // <--- The program shall exit on \nEOF here, but it 
 // spins inside ngets() and does not reach this point
                    break;
    }
    return 0;
}

$ echo "balbalbalabl" | ./bget &
$

There is no problem in libstand when it is used in the real boot loader, but inside
bhyveload it has a bug described above.

There is a github pull request with suggested patch

https://github.com/freebsd/freebsd/pull/23
Comment 1 Bryan Drewery freebsd_committer freebsd_triage 2016-03-04 23:23:43 UTC
Can you show an example of what you're doing with bhyve? When I try to pipe input in the vm just exits on the EOF.
Comment 2 commit-hook freebsd_committer freebsd_triage 2018-08-09 02:56:50 UTC
A commit references this bug:

Author: kevans
Date: Thu Aug  9 02:55:48 UTC 2018
New revision: 337523
URL: https://svnweb.freebsd.org/changeset/base/337523

Log:
  libsa: exit on EOF in ngets

  It was possible in some rare circumstances for ngets to behave terribly with
  bhyveload and some form of redirecting user input over a pipe.

  PR:		198706
  Submitted by:	Ivan Krivonos <int0dster@gmail.com>
  MFC after:	1 week

Changes:
  head/stand/libsa/gets.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2018-08-20 00:49:25 UTC
A commit references this bug:

Author: kevans
Date: Mon Aug 20 00:49:06 UTC 2018
New revision: 338077
URL: https://svnweb.freebsd.org/changeset/base/338077

Log:
  MFC r337523: libsa: exit on EOF in ngets

  It was possible in some rare circumstances for ngets to behave terribly with
  bhyveload and some form of redirecting user input over a pipe.

  PR:		198706

Changes:
_U  stable/11/
  stable/11/stand/libsa/gets.c
Comment 4 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-21 10:07:06 UTC
There is a commit referencing this PR, but it's still not closed and has been inactive for some time. Closing the PR as fixed but feel free to re-open it if the issue hasn't been completely resolved.

Thanks