From e133742d76872a3c5de24288ab012e4831d38d75 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 9 May 2018 18:28:04 -0700 Subject: [PATCH] af_alg: fix my typo in afalg_buffer * lib/af_alg.c (afalg_buffer): Fix typo I recently introduced. (afalg_stream): Simplify and avoid the need for a runtime test at the end. --- ChangeLog | 5 +++++ lib/af_alg.c | 19 ++++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4eb0958583..420426fe11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2018-05-09 Paul Eggert + af_alg: fix my typo in afalg_buffer + * lib/af_alg.c (afalg_buffer): Fix typo I recently introduced. + (afalg_stream): Simplify and avoid the need for a runtime test + at the end. + af_alg: recover better from crypto failures * lib/af_alg.c (afalg_stream): Recover from crypto failures if the input stream is seekable, by repositioning the stream back to diff --git a/lib/af_alg.c b/lib/af_alg.c index 677a8e3404..ded4b326b7 100644 --- a/lib/af_alg.c +++ b/lib/af_alg.c @@ -86,7 +86,7 @@ afalg_buffer (const char *buffer, size_t len, const char *alg, len -= size; if (len == 0) { - result = read (ofd, resblock, hashlen) == hashlen ? -EAFNOSUPPORT: 0; + result = read (ofd, resblock, hashlen) == hashlen ? 0 : -EAFNOSUPPORT; break; } } @@ -108,7 +108,7 @@ afalg_stream (FILE *stream, const char *alg, with /proc files that pretend to be empty, and lets the classic read-write loop work around an empty-input bug noted below. */ int fd = fileno (stream); - int result = 0; + int result; struct stat st; off_t nseek = 0, off = ftello (stream); if (0 <= off && fstat (fd, &st) == 0 @@ -116,8 +116,7 @@ afalg_stream (FILE *stream, const char *alg, && off < st.st_size && st.st_size - off < SYS_BUFSIZE_MAX) { off_t nbytes = st.st_size - off; - if (sendfile (ofd, fd, &off, nbytes) != nbytes) - result = -EAFNOSUPPORT; + result = sendfile (ofd, fd, &off, nbytes) == nbytes ? 0 : -EAFNOSUPPORT; } else { @@ -132,17 +131,14 @@ afalg_stream (FILE *stream, const char *alg, { /* On Linux < 4.9, the value for an empty stream is wrong (all 0). See . */ - if (nseek == 0) - result = -EAFNOSUPPORT; - - if (ferror (stream)) - result = -EIO; + result = ferror (stream) ? -EIO : nseek == 0 ? -EAFNOSUPPORT : 0; break; } nseek -= size; if (send (ofd, buf, size, MSG_MORE) != size) { - result = -EAFNOSUPPORT; + result = (fseeko (stream, nseek, SEEK_CUR) == 0 + ? -EAFNOSUPPORT : -EIO); break; } } @@ -151,9 +147,6 @@ afalg_stream (FILE *stream, const char *alg, if (result == 0 && read (ofd, resblock, hashlen) != hashlen) result = -EAFNOSUPPORT; close (ofd); - if (result == -EAFNOSUPPORT && nseek != 0 - && fseeko (stream, nseek, SEEK_CUR) != 0) - result = -EIO; return result; } -- 2.39.5