From: Kamil Dudka <kdudka@redhat.com>
To: Bruno Haible <bruno@clisp.org>
Cc: Paul Eggert <eggert@cs.ucla.edu>, bug-gnulib@gnu.org
Subject: Re: Coverity false positives triggered by gnulib's implementation of base64
Date: Fri, 10 May 2019 16:32:16 +0200 [thread overview]
Message-ID: <2074537.q5eH3G9g4i@kdudka-nb> (raw)
In-Reply-To: <2726075.gEfPVFXcrz@omega>
On Friday, May 10, 2019 4:11:45 PM CEST Bruno Haible wrote:
> Kamil Dudka wrote:
> > Thanks! This also helps to suppress the false positives on cryptsetup
> > with Coverity Static Analysis version 2019.03.
>
> Good! Since this is the approach that Paul prefers, I'm pushing this one:
>
>
> 2019-05-10 Bruno Haible <bruno@clisp.org>
>
> base64: Avoid false positive warning from Coverity.
> Reported by Kamil Dudka <kdudka@redhat.com>.
> Idea by Paul Eggert.
> * lib/base64.c (base64_encode_fast, base64_encode): Add a no-op
> '& 0x3f' to the array index expressions. This convinces Coverity that
> there is no out-of-bounds array reference, regardless of the input.
>
> diff --git a/lib/base64.c b/lib/base64.c
> index f3f7298..a00e0f4 100644
> --- a/lib/base64.c
> +++ b/lib/base64.c
> @@ -70,7 +70,7 @@ base64_encode_fast (const char *restrict in, size_t inlen,
> char *restrict out) {
> while (inlen)
> {
> - *out++ = b64c[to_uchar (in[0]) >> 2];
> + *out++ = b64c[(to_uchar (in[0]) >> 2) & 0x3f];
> *out++ = b64c[((to_uchar (in[0]) << 4) + (to_uchar (in[1]) >> 4)) &
> 0x3f]; *out++ = b64c[((to_uchar (in[1]) << 2) + (to_uchar (in[2]) >> 6)) &
> 0x3f]; *out++ = b64c[to_uchar (in[2]) & 0x3f];
> @@ -103,7 +103,7 @@ base64_encode (const char *restrict in, size_t inlen,
>
> while (inlen && outlen)
> {
> - *out++ = b64c[to_uchar (in[0]) >> 2];
> + *out++ = b64c[(to_uchar (in[0]) >> 2) & 0x3f];
> if (!--outlen)
> break;
> *out++ = b64c[((to_uchar (in[0]) << 4)
Works for me. Thanks to both of you!
Kamil
next prev parent reply other threads:[~2019-05-10 14:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-07 14:22 Coverity false positives triggered by gnulib's implementation of base64 Kamil Dudka
2019-05-08 8:15 ` Bruno Haible
2019-05-09 16:14 ` Kamil Dudka
2019-05-09 20:35 ` Bruno Haible
2019-05-09 21:55 ` Paul Eggert
2019-05-09 22:13 ` Bruno Haible
2019-05-09 22:28 ` Paul Eggert
2019-05-10 11:57 ` Kamil Dudka
2019-05-10 14:11 ` Bruno Haible
2019-05-10 14:32 ` Kamil Dudka [this message]
2019-05-10 11:41 ` Kamil Dudka
2019-05-09 19:14 ` Paul Eggert
2019-05-10 11:32 ` Kamil Dudka
2019-05-10 11:34 ` Florian Weimer
2019-05-10 11:51 ` Kamil Dudka
2019-05-10 23:36 ` Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2074537.q5eH3G9g4i@kdudka-nb \
--to=kdudka@redhat.com \
--cc=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=eggert@cs.ucla.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).