This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PING 2] [PATCH] c++/67942 - diagnose placement new buffer overflow
- From: Martin Sebor <msebor at gmail dot com>
- To: Jason Merrill <jason at redhat dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 05 Nov 2015 16:41:36 -0700
- Subject: Re: [PING 2] [PATCH] c++/67942 - diagnose placement new buffer overflow
- Authentication-results: sourceware.org; auth=none
- References: <561D3DEC dot 5090209 at gmail dot com> <5626D4D0 dot 4010603 at gmail dot com> <562ED7E4 dot 8030001 at gmail dot com> <56381EB8 dot 4090708 at redhat dot com> <563A3C45 dot 1060907 at gmail dot com> <563A58AB dot 608 at redhat dot com> <563A9FAD dot 2050807 at gmail dot com> <563ADAA2 dot 9090702 at redhat dot com> <563B71F5 dot 8030902 at gmail dot com> <563B7541 dot 3010902 at redhat dot com> <563B8953 dot 20901 at gmail dot com> <563B9C3C dot 2010404 at redhat dot com>
On 11/05/2015 11:13 AM, Jason Merrill wrote:
OK, thanks.
I'm afraid the last patch that I just committed breaks libstdc++
bootstrap with the following error:
/home/msebor/scm/fsf/gcc-svn/libstdc++-v3/src/c++98/ios_init.cc: In
static member function âstatic bool std::ios_base::sync_with_stdio(bool)â:
/home/msebor/scm/fsf/gcc-svn/libstdc++-v3/src/c++98/ios_init.cc:181:59:
internal compiler error: in tree_to_shwi, at tree.c:7297
new (&buf_cout) stdio_filebuf<char>(stdout, ios_base::out);
I thought it had something to do with the recent changes made to
the patch but it looks like it's a problem that's been there all
along: the patch assumes DECL_SIZE_UNIT (oper) is non-null but
it turns out that's not a safe assumption. I don't know why my
testing didn't expose it before, despite running make bootstrap
and make check.
The following patch (only the first bit is important) fixes the
ICE. I will commit it as soon as I'm done testing it.
Sorry about the breakage.
Martin
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 7600363..ca7de56 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -2384,12 +2384,13 @@ warn_placement_new_too_small (tree type, tree
nelts, tree size, tree oper)
/* Treat members of unions and members of structs uniformly, even
though the size of a member of a union may be viewed as extending
to the end of the union itself (it is by
__builtin_object_size). */
- if (TREE_CODE (oper) == VAR_DECL || use_obj_size)
+ if ((TREE_CODE (oper) == VAR_DECL || use_obj_size)
+ && (DECL_SIZE_UNIT (oper)))
{
/* Use the size of the entire array object when the expression
refers to a variable or its size depends on an expression
that's not a compile-time constant. */
- bytes_avail = tree_to_shwi (DECL_SIZE_UNIT (oper));
+ bytes_avail = tree_to_uhwi (DECL_SIZE_UNIT (oper));
exact_size = !use_obj_size;
}
else