From: Martin Sebor <msebor@gmail.com>
To: Florian Weimer <fweimer@redhat.com>,
Martin Sebor via Libc-alpha <libc-alpha@sourceware.org>
Cc: Joseph Myers <joseph@codesourcery.com>
Subject: Re: [PATCH] more out of bounds checking improvements
Date: Mon, 10 May 2021 11:14:01 -0600 [thread overview]
Message-ID: <7da0198c-a478-d877-4b64-da5a50e7e87b@gmail.com> (raw)
In-Reply-To: <87fsyvf04w.fsf@oldenburg.str.redhat.com>
On 5/10/21 2:45 AM, Florian Weimer wrote:
> * Martin Sebor via Libc-alpha:
>
>> diff --git a/nss/makedb.c b/nss/makedb.c
>> index 74edb749cf..9389f6b548 100644
>> --- a/nss/makedb.c
>> +++ b/nss/makedb.c
>> @@ -747,7 +747,8 @@ write_output (int fd)
>> header->valstrlen = valstrlen;
>>
>> size_t filled_dbs = 0;
>> - struct iovec iov[2 + ndatabases * 3];
>> + size_t iov_nelts = 2 + ndatabases * 3;
>> + struct iovec iov[iov_nelts];
>> iov[0].iov_base = header;
>> iov[0].iov_len = file_offset;
>>
>> @@ -791,7 +792,9 @@ write_output (int fd)
>> + nhashentries_total * sizeof (stridx_t)));
>> header->allocate = file_offset;
>>
>> - if (writev (fd, iov, 2 + ndatabases * 3) != keydataoffset)
>> + /* Help GCC 10 see iov_nelts doesn't overflow the writev argument. */
>> + assert (iov_nelts <= INT_MAX);
>> + if (writev (fd, iov, iov_nelts) != keydataoffset)
>> {
>> error (0, errno, gettext ("failed to write new database file"));
>> return EXIT_FAILURE;
>
> I don't think you should use assert to suppress compiler warnings
> because we are supposed to have warning-free builds even with -DNDEBUG
> (although it's likely that other problems exist).
So how about the following instead of the assert?
diff --git a/nss/makedb.c b/nss/makedb.c
index 9389f6b548..6551b3cf2a 100644
--- a/nss/makedb.c
+++ b/nss/makedb.c
@@ -792,14 +792,25 @@ write_output (int fd)
+ nhashentries_total * sizeof (stridx_t)));
header->allocate = file_offset;
- /* Help GCC 10 see iov_nelts doesn't overflow the writev argument. */
assert (iov_nelts <= INT_MAX);
+
+#if __GNUC_PREREQ (10, 0)
+ DIAG_PUSH_NEEDS_COMMENT;
+ /* Avoid GCC 10 false positice warning: specified size exceeds maximum
+ object size. */
+ DIAG_IGNORE_NEEDS_COMMENT (10, "-Wstringop-overflow");
+#endif
+
if (writev (fd, iov, iov_nelts) != keydataoffset)
{
error (0, errno, gettext ("failed to write new database file"));
return EXIT_FAILURE;
}
+#if __GNUC_PREREQ (10, 0)
+ DIAG_POP_NEEDS_COMMENT;
+#endif
+
return EXIT_SUCCESS;
}
Martin
next prev parent reply other threads:[~2021-05-10 17:14 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 15:01 Martin Sebor
2020-10-26 15:41 ` Florian Weimer
2020-12-09 0:18 ` Martin Sebor
2020-10-26 16:08 ` Joseph Myers
2020-12-09 21:46 ` Martin Sebor
2020-12-18 16:56 ` Ping: " Martin Sebor
2021-01-04 15:54 ` Ping 2: " Martin Sebor
2021-01-10 20:44 ` Ping 3: " Martin Sebor
2021-04-22 21:36 ` Ping 4: " Martin Sebor
2021-04-23 10:31 ` Florian Weimer
2021-04-23 15:06 ` Martin Sebor
2021-04-23 16:01 ` Florian Weimer
2021-05-04 19:58 ` Martin Sebor
2021-05-06 17:03 ` Martin Sebor
2021-05-06 18:15 ` Joseph Myers
2021-05-06 19:40 ` Martin Sebor
2021-05-07 9:20 ` Andreas Schwab
2021-05-07 9:24 ` Florian Weimer
2021-05-07 11:48 ` Andreas Schwab
2021-05-07 19:30 ` Tulio Magno Quites Machado Filho
2021-05-10 17:23 ` Joseph Myers
2021-05-10 8:45 ` Florian Weimer
2021-05-10 17:14 ` Martin Sebor [this message]
2021-05-10 17:49 ` Florian Weimer
2021-05-10 18:37 ` Martin Sebor
2021-05-10 19:22 ` Andreas Schwab
2021-05-10 19:50 ` Florian Weimer
2021-05-10 20:31 ` Martin Sebor
2021-05-11 10:53 ` Florian Weimer
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7da0198c-a478-d877-4b64-da5a50e7e87b@gmail.com \
--to=msebor@gmail.com \
--cc=fweimer@redhat.com \
--cc=joseph@codesourcery.com \
--cc=libc-alpha@sourceware.org \
/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).