From 20841b57543a5ca8fd189d74a59d0cadede87cd2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 25 Jun 2018 00:25:31 +0200 Subject: [PATCH] af_alg: Comment and style improvements. * lib/af_alg.c (alg_socket): Use 'size_t' as index into a string. (afalg_buffer, afalg_stream): Improve comments. --- ChangeLog | 6 ++++++ lib/af_alg.c | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10372203bc..0b2f6a9228 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-06-24 Bruno Haible + + af_alg: Comment and style improvements. + * lib/af_alg.c (alg_socket): Use 'size_t' as index into a string. + (afalg_buffer, afalg_stream): Improve comments. + 2018-06-24 Pádraig Brady af_alg: disable kernel hash functions by default diff --git a/lib/af_alg.c b/lib/af_alg.c index 9630d03912..33d883736b 100644 --- a/lib/af_alg.c +++ b/lib/af_alg.c @@ -44,9 +44,10 @@ alg_socket (char const *alg) .salg_family = AF_ALG, .salg_type = "hash", }; - /* Avoid calling both strcpy and strlen. */ - for (int i = 0; (salg.salg_name[i] = alg[i]); i++) + /* Copy alg into salg.salg_name, without calling strcpy nor strlen. */ + for (size_t i = 0; (salg.salg_name[i] = alg[i]) != '\0'; i++) if (i == sizeof salg.salg_name - 1) + /* alg is too long. */ return -EINVAL; int cfd = socket (AF_ALG, SOCK_SEQPACKET | SOCK_CLOEXEC, 0); @@ -64,7 +65,9 @@ afalg_buffer (const char *buffer, size_t len, const char *alg, void *resblock, ssize_t hashlen) { /* On Linux < 4.9, the value for an empty stream is wrong (all zeroes). - See . */ + See . + This was not fixed properly until November 2016, + see . */ if (len == 0) return -EAFNOSUPPORT; @@ -110,7 +113,8 @@ afalg_stream (FILE *stream, const char *alg, int fd = fileno (stream); int result; struct stat st; - off_t nseek = 0, off = ftello (stream); + off_t nseek = 0; /* Number of bytes to seek (backwards) in case of error. */ + off_t off = ftello (stream); if (0 <= off && fstat (fd, &st) == 0 && (S_ISREG (st.st_mode) || S_TYPEISSHM (&st) || S_TYPEISTMO (&st)) && off < st.st_size && st.st_size - off < SYS_BUFSIZE_MAX) @@ -120,7 +124,7 @@ afalg_stream (FILE *stream, const char *alg, } else { - /* sendfile not possible, do a classic read-write loop. */ + /* sendfile not possible, do a classic read-write loop. */ for (;;) { char buf[BLOCKSIZE]; @@ -128,7 +132,9 @@ afalg_stream (FILE *stream, const char *alg, if (size == 0) { /* On Linux < 4.9, the value for an empty stream is wrong (all 0). - See . */ + See . + This was not fixed properly until November 2016, + see . */ result = ferror (stream) ? -EIO : nseek == 0 ? -EAFNOSUPPORT : 0; break; } -- 2.39.5