[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Fix use of sockaddr_in

From: Paul Eggert
Subject: Re: [PATCH] Fix use of sockaddr_in
Date: Wed, 17 May 2017 13:38:41 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0

On 05/15/2017 02:04 AM, Philipp Stephani wrote:
- Maybe add verify(INT_MAX >= TYPE_MAXIMUM(in_port_t)) and verify(TYPE_MINIMUM(in_port_t) == 0) to make sure that we can use int for the port?

The code has been changed so that the port number is no longer stored in an int so this remark is obsolete now. However, if this issue crops up later I don't think we need to worry about it for IPv4 and IPv6 ports, since they're always in the range 0..65535. Emacs already assumes that 'int' is at least 32 bits wide, as per POSIX.

- Should there be a guard against the alias violation, e.g. by declaring sa and sa1 with __attribute__((may_alias))? Otherwise it's UB and the compiler might elide the switch entirely.

Yes, that is easy enough to do and would avoid some unlikely but hard-to-catch bugs. I installed the attached. Most likely other parts of Emacs should use may_alias too; do you happen to have any tool in your toolbox that would find them systematically?

Attachment: 0001-Avoid-undefined-behavior-in-struct-sockaddr.patch
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]