This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix Stack Smashing Protector to protect functions with wchar_t arrays


The Stack Smashing Protector does not include functions with wide
character arrays. The following code wouldn't be protected:

#include <wchar.h>

int main (void) {
        wchar_t buf[8];

        wcscpy (buf, L"Hello World!");

        return 0;
}

Attached patch solves this problem. Tested on i686
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c	(revision 140598)
+++ gcc/cfgexpand.c	(working copy)
@@ -41,6 +41,7 @@
 #include "tree-inline.h"
 #include "value-prof.h"
 #include "target.h"
+#include "c-common.h"
 
 
 /* Return an expression tree corresponding to the RHS of GIMPLE
@@ -1201,7 +1202,10 @@
       t = TYPE_MAIN_VARIANT (TREE_TYPE (type));
       if (t == char_type_node
 	  || t == signed_char_type_node
-	  || t == unsigned_char_type_node)
+	  || t == unsigned_char_type_node
+	  || t == wchar_type_node
+	  || t == signed_wchar_type_node
+	  || t == unsigned_wchar_type_node)
 	{
 	  unsigned HOST_WIDE_INT max = PARAM_VALUE (PARAM_SSP_BUFFER_SIZE);
 	  unsigned HOST_WIDE_INT len;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]