git: 172be8642d93 - main - split: reset errno prior to getline()

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Thu, 27 Oct 2022 17:19:13 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=172be8642d93851b0c083d0db240cf35fd56ab0e

commit 172be8642d93851b0c083d0db240cf35fd56ab0e
Author:     Math Ieu <sigsys@gmail.com>
AuthorDate: 2022-10-27 17:01:57 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2022-10-27 17:17:59 +0000

    split: reset errno prior to getline()
    
    Something else may have set errno, breaking the post-getline() logic
    that tries to detect the getline() error.  This was initially noted in
    a jail on a system that has HPET, in a jail that does not expose
    /dev/hpet0 -- we see an earlier error in libc's vdso bits.
    
    Fixes:  5c053aa3c5e90 ("split: switch to getline() [...]")
---
 usr.bin/split/split.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr.bin/split/split.c b/usr.bin/split/split.c
index 008b614f4946..091c914ba8f7 100644
--- a/usr.bin/split/split.c
+++ b/usr.bin/split/split.c
@@ -278,7 +278,7 @@ split2(void)
 		err(EX_NOINPUT, "fdopen");
 
 	/* Process input one line at a time */
-	while ((len = getline(&buf, &bufsize, infp)) > 0) {
+	while ((errno = 0, len = getline(&buf, &bufsize, infp)) > 0) {
 		/* Check if we need to start a new file */
 		if (pflag) {
 			regmatch_t pmatch;