[dpdk-dev] [PATCH] hash: fix breaking strict-aliasing rules

Жумабеков Ерден Мирзагулович E_Zhumabekov at sts.kz
Sat Mar 21 07:57:05 CET 2015


Hi Pawel,

Oops, thanks for the clue. I have a buffer over-read here leading to undefined behaviour.
The only solution I see here is to declare uint32_t pointer and evaluate it to (uint8_t *) data + data_len - (data_len & 0x07). Ideas are welcome. That would resolve strict-aliasing violation.
_____________________
From: Pawel Wodkowski [pawelx.wodkowski at intel.com]
Sent: Friday, March 20, 2015 18:47
To: Жумабеков Ерден Мирзагулович; dev at dpdk.org
Subject: Re: [dpdk-dev] [PATCH] hash: fix breaking strict-aliasing rules

On 2015-03-18 17:51, Yerden Zhumabekov wrote:

>
> -     switch (7 - (data_len & 0x07)) {
> +     i = 7 - (data_len & 0x07);
> +     switch (i) {
>       case 0:
> -             temp |= (uint64_t) *((const uint8_t *)p64 + 6) << 48;
> -             /* Fallthrough */
>       case 1:
> -             temp |= (uint64_t) *((const uint8_t *)p64 + 5) << 40;
> -             /* Fallthrough */
>       case 2:
> -             temp |= (uint64_t) *((const uint8_t *)p64 + 4) << 32;
> -             temp |= *((const uint32_t *)p64);
> +             temp = odd_8byte_mask[i] & *p64;
>               init_val = rte_hash_crc_8byte(temp, init_val);
>               break;
>       case 3:
> -             init_val = rte_hash_crc_4byte(*(const uint32_t *)p64, init_val);
> -             break;
>       case 4:
> -             temp |= *((const uint8_t *)p64 + 2) << 16;
> -             /* Fallthrough */
>       case 5:
> -             temp |= *((const uint8_t *)p64 + 1) << 8;
> -             /* Fallthrough */
>       case 6:
> -             temp |= *((const uint8_t *)p64);
> +             temp = odd_8byte_mask[i] & *p64;
>               init_val = rte_hash_crc_4byte(temp, init_val);
> -             /* Fallthrough */
>       default:
>               break;
>       }
>

Second thought: is this not an issue here reading 8 bytes by
dereferencing *p64 if there is less bytes in buffer?

--
Pawel


More information about the dev mailing list