lkml.org 
[lkml]   [2021]   [Aug]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] staging: r8188eu: Fix different base types in assignments and parameters
On Fri, Jul 30, 2021 at 08:14:52PM +0200, Fabio M. De Francesco wrote:
> static inline void __nat25_generate_ipx_network_addr_with_socket(unsigned char *networkAddr,
> - unsigned int *ipxNetAddr, unsigned short *ipxSocketAddr)
> + __be32 *ipxNetAddr, __be16 *ipxSocketAddr)
> {
> + union {
> + unsigned int f0;
> + unsigned char f1[4];
> + } addr;
> +
> memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
>
> networkAddr[0] = NAT25_IPX;
> - memcpy(networkAddr+1, (unsigned char *)ipxNetAddr, 4);
> - memcpy(networkAddr+5, (unsigned char *)ipxSocketAddr, 2);
> + addr.f0 = be32_to_cpu(*ipxNetAddr);
> + memcpy(networkAddr+1, addr.f1, 4);
> + addr.f0 ^= addr.f0;
> + addr.f0 = be16_to_cpu(*ipxSocketAddr);
> + memcpy(networkAddr+5, addr.f1, 2);

Here is another bug which was obscured/caused by the union.

addr.f0 = be16_to_cpu(*ipxSocketAddr);

The addr.f0 variable is an int. On big endian systems only the last two
bytes are set:

memcpy(networkAddr+5, addr.f1, 2);

So this is the equivalent of:

memset(networkAddr+5, 0, 2);

regards,
dan carpenter

\
 
 \ /
  Last update: 2021-08-04 10:00    [W:0.113 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site