Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible buffer overruns in l9p_start_server #7

Open
kimshrier opened this issue Jan 6, 2017 · 0 comments
Open

Possible buffer overruns in l9p_start_server #7

kimshrier opened this issue Jan 6, 2017 · 0 comments

Comments

@kimshrier
Copy link
Contributor

The arrays kev, event, and sockets, are allocated with a fixed size of 2. These arrays are populated with values derived from the result list returned from getaddrinfo. It is possible for getaddrinfo to return more than 2 addrinfo values in its return list. In the event that it does and that sockets are successfully created from each one, the sockets array would be overrun. In the following code that sets up event handlers for these sockets, the kev and event arrays would be overrun as well.

There are 2 ways to fix the problem. Either limit the for loop that runs the addrinfo list to 2, or malloc the kev, event, and sockets arrays based on the number of entries in the return list. In the case of limiting the for loop, I would make a define for the number of entries in these arrays and use the same defined value in the for loop. Something like:

#define MAXSOCK 2

...

struct kevent kev[MAXSOCK];
struct kevent event[MAXSOCK];
int sockets[MAXSOCK];

...

for (res = res0; res && nsockets < MAXSOCK; res = res->ai_next) {

I can submit a pull request for either solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant