Get the latest tech news

The trouble with struct sockaddr's fake flexible array


many faces of struct sockaddr The sockaddr structure dates back to the beginning of the BSD socket API; it is used to hold an address corresponding to one side of a network connection. The 4.2 BSD networking implementation notes from 1983 give its format as: struct sockaddr { short sa_family; char sa_data[14]; }; The sa_family field describes which address family is in use — AF_INET for an IPv4 address, for example.

That has the result of placing a flexible array in the middle of the embedding structure, which is problematic for fairly obvious reasons; the compiler no longer knows what the offsets to the members after struct sockaddr should be. It also, as Cook noted in the cover letter, is still lying to the compiler in cases where the backing structure is actually smaller than struct sockaddr_storage, " these remain just as safe as they used to be. This series shows that truly eliminating the use of this structure's sa_data field as a flexible array in disguise will involve a fair amount of work and code churn.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Trouble

Trouble

Photo of fake flexible array

fake flexible array

Photo of struct sockaddr

struct sockaddr

Related news:

News photo

Ex-Google CEO warns that 'perfect' AI girlfriends could spell trouble for young men | He suggested AI regulation changes but expects little action without a major incident.

News photo

MKBHD got himself in trouble again

News photo

The images of Spain’s floods weren’t created by AI. The trouble is, people think they were