From: Tim Hallmann Date: Sun, 24 Mar 2024 19:14:30 +0000 (+0100) Subject: rev: Check for wchar conversion errors X-Git-Tag: v2.42-start~477 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a610cf8231a02163a4a2b2faf3047d24798fe180;p=thirdparty%2Futil-linux.git rev: Check for wchar conversion errors Commit c9cc84621ca98ef85499e83ca56f05f12055f193 introduced a regression where only the actual EOF is handled, not other error conditions returning WEOF. This leads to an infinite loop upon encountering conversion errors. For example (using LC_CTYPE="en_US.UTF-8"): $ printf '\x80' | rev Signed-off-by: Tim Hallmann --- diff --git a/text-utils/rev.c b/text-utils/rev.c index 81331719d..4b731890d 100644 --- a/text-utils/rev.c +++ b/text-utils/rev.c @@ -173,8 +173,6 @@ int main(int argc, char *argv[]) line = 0; while (!feof(fp)) { len = read_line(sep, buf, bufsiz, fp); - if (len == 0) - continue; /* This is my hack from setpwnam.c -janl */ while (len == bufsiz && !feof(fp)) { @@ -187,14 +185,18 @@ int main(int argc, char *argv[]) /* And fill the rest of the buffer */ len += read_line(sep, &buf[len], bufsiz/2, fp); } + if (ferror(fp)) { + warn("%s: %ju", filename, line); + rval = EXIT_FAILURE; + break; + } + if (len == 0) + continue; + reverse_str(buf, buf[len - 1] == sep ? len - 1 : len); write_line(buf, len, stdout); line++; } - if (ferror(fp)) { - warn("%s: %ju", filename, line); - rval = EXIT_FAILURE; - } if (fp != stdin) fclose(fp); } while(*argv);