rev: Check for wchar conversion errors
PATCH 1/1 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 <[email protected]>
--- text-utils/rev.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
text-utils/rev.c +8 -6
@@ -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);
Signature · 1 line
2.44.0
Karel Zak
maintainerQuoted 2 lines · Tim Hallmann
text-utils/rev.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
Looks good, I've created PR
https://github.com/util-linux/util-linux/pull/2854 to verify the change against our tests.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com