joswa / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Non-thread-safe use of inet_ntoa #297

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Mongoose seems to call inet_ntoa from various places in worker threads. 
inet_ntoa is documented in man pages as returning a pointer to a 
statically-allocated buffer, so it may corrupt the buffer if two threads 
(either two Mongoose threads, or Mongoose plus an application it's embedded in) 
run it simultaneously.

(http://www.apsis.ch/pound/pound_list/archive/2006/2006-07/1151745756000 
reports the kinds of errors this can lead to.)

In practice, at least recent versions of glibc use a per-thread buffer, and 
MSDN says the buffer is valid until the next WinSock call on the same thread, 
so they'll be safe, but other implementations might vary.

inet_ntop with a caller-allocated buffer looks like the right way to fix this.

Original issue reported on code.google.com by exc...@gmail.com on 23 Nov 2011 at 11:14