al45tair / netifaces

MIT License
327 stars 82 forks source link

Invalid errno check in netifaces.gateways() #28

Closed asomers closed 5 years ago

asomers commented 5 years ago

At https://github.com/al45tair/netifaces/blob/b8662eca722ee3417c433468cb6041440d0af8c9/netifaces.c#L2010, gateways() will loop if the condition ret != 0 || errno == ENOMEM || errno == EINTR is true. However, that condition is invalid. If ret is 0, then errno is undefined. It may contain a value leftover from the caller of gateways, or it may contain an error that was internally handled by sysctl(3). Also, the fact that the very next line checks for negative values of ret implies that the condtion is wrong; as-is, ret can never be negative at that point. The condition should probably read ret != 0 && (errno == ENOMEM || errno == EINTR).

I think this is the root cause of https://github.com/iocage/iocage/issues/766 .

al45tair commented 5 years ago

Agreed, that's clearly wrong. Thanks for the fix.