[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] hw/net/e1000: fix integer endianness
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH] hw/net/e1000: fix integer endianness |
Date: |
Fri, 13 Mar 2015 13:51:34 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
On 13/03/2015 06:21, Shannon Zhao wrote:
> It's detected by coverity.In is_vlan_packet s->mac_reg[VET] is
> unsigned int but is dereferenced as a narrower unsigned short.
> This may lead to unexpected results depending on machine
> endianness.
Sounds good. CCing Stefan, net/ maintainer.
> Signed-off-by: Shannon Zhao <address@hidden>
> Signed-off-by: Shannon Zhao <address@hidden>
> ---
> hw/net/e1000.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/net/e1000.c b/hw/net/e1000.c
> index a207e21..59d73cd 100644
> --- a/hw/net/e1000.c
> +++ b/hw/net/e1000.c
> @@ -578,7 +578,7 @@ static inline int
> is_vlan_packet(E1000State *s, const uint8_t *buf)
> {
> return (be16_to_cpup((uint16_t *)(buf + 12)) ==
> - le16_to_cpup((uint16_t *)(s->mac_reg + VET)));
> + le16_to_cpu(s->mac_reg[VET]));
> }
>
> static inline int
> @@ -711,7 +711,7 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
> (tp->cptse || txd_lower & E1000_TXD_CMD_EOP)) {
> tp->vlan_needed = 1;
> stw_be_p(tp->vlan_header,
> - le16_to_cpup((uint16_t *)(s->mac_reg + VET)));
> + le16_to_cpu(s->mac_reg[VET]));
> stw_be_p(tp->vlan_header + 2,
> le16_to_cpu(dp->upper.fields.special));
> }
>