[PATCH] Fix stack_protect_classify_type
Jakub Jelinek
jakub@redhat.com
Sat Jul 9 19:52:00 GMT 2005
Hi!
stack_protect_classify_type considers char arrays whose max value of the
array domain is smaller than --param ssp-buffer-size.
But this doesn't correspond with -Wstack-protector, where the warning
says:
if (has_short_buffer && !cfun->stack_protect_guard)
warning (0, "not protecting function: no buffer at least %d bytes long",
(int) PARAM_VALUE (PARAM_SSP_BUFFER_SIZE));
The following patch changes stack_protect_classify_type to use
TYPE_SIZE_UNIT instead, which is array size in bytes. As host_integerp
is used with second argument 1, I have also used unsigned HOST_WIDE_INT
instead of HOST_WIDE_INT.
With this patch, char buf[8] with the default ssp-buffer-size param (8)
will already use the stack canary, while with --param ssp-buffer-size=9
it will not.
Ok to commit?
2005-07-09 Jakub Jelinek <jakub@redhat.com>
* cfgexpand.c (stack_protect_classify_type): Use TYPE_SIZE_UNIT (type)
instead of TYPE_MAX_VALUE (TYPE_DOMAIN (type)) to get array size in
bytes.
--- gcc/cfgexpand.c.jj 2005-07-09 21:20:07.000000000 +0200
+++ gcc/cfgexpand.c 2005-07-09 21:40:41.000000000 +0200
@@ -770,15 +770,14 @@ stack_protect_classify_type (tree type)
|| t == signed_char_type_node
|| t == unsigned_char_type_node)
{
- HOST_WIDE_INT max = PARAM_VALUE (PARAM_SSP_BUFFER_SIZE);
- HOST_WIDE_INT len;
+ unsigned HOST_WIDE_INT max = PARAM_VALUE (PARAM_SSP_BUFFER_SIZE);
+ unsigned HOST_WIDE_INT len;
- if (!TYPE_DOMAIN (type)
- || !TYPE_MAX_VALUE (TYPE_DOMAIN (type))
- || !host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 1))
- len = max + 1;
+ if (!TYPE_SIZE_UNIT (type)
+ || !host_integerp (TYPE_SIZE_UNIT (type), 1))
+ len = max;
else
- len = tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 1);
+ len = tree_low_cst (TYPE_SIZE_UNIT (type), 1);
if (len < max)
ret = SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_ARRAY;
Jakub
More information about the Gcc-patches
mailing list