114 Commits

Author SHA1 Message Date
Nick Mathewson
336dcaeaef Fix a compilation error with MSVC 2005 due to use of mode_t
MSVC apparently doesn't have a mode_t defined, though mingw does.

Found by Savg He.
2012-03-30 10:26:50 -04:00
Nick Mathewson
03dce42dfa Tweak the evutil_open_closeonexec patch to work on windows, old unixes.
Windows doesn't have a mode_t as far as I can tell.

Some unixes, iirc, don't like three-argument open without O_CREAT.
2012-02-11 21:17:18 -05:00
Ross Lagerwall
d2b5f7223a Make uses of open() close-on-exec safe by introducing evutil_open_closeonexec.
In a multi-process/threaded environment, opening fds internally
without the close-on-exec flag could leak fds to child processes.
2012-02-11 21:10:22 -05:00
Nick Mathewson
e49e289129 Update copyright notices to 2012 2012-02-10 17:29:53 -05:00
Nick Mathewson
3c824bd334 Update copyright dates to 2011. 2011-10-24 13:18:09 -04:00
Harlan Stenn
7c11e51e1a Clean up some problems identified by Coverity. 2011-08-28 13:44:33 -04:00
Nicholas Marriott
8ee9f9c1cf Fix a few warnings on OpenBSD
- redeclaration of dst_size

- arpa/inet.h requires netinet/in.h first

- don't use a local with the same name as a global - it isn't needed so
  remove it
2011-07-02 21:49:07 -04:00
Nick Mathewson
1a21d7b840 Fix the check for multicast or broadcast addresses in evutil_check_interfaces
First of all, it is totally okay to have an address end with .255,
depending on what your netmask is, so we shouldn't reject a local
address if it ends with .255.

Second, our check for ending with .255 was broken.  So was our check
for class-d addresses.

Found by Dave Hart.
2011-04-05 17:21:14 -04:00
Nick Mathewson
637d17a1b9 Check for allocation failures in apply_socktype_protocol_hack 2011-04-05 16:32:39 -04:00
Nick Mathewson
3c8f4e758e Add compile-time check for AF_UNSPEC==PF_UNSPEC 2011-01-31 16:44:06 -05:00
Nick Mathewson
cb92113979 Build on systems without AI_PASSIVE 2011-01-31 16:32:05 -05:00
Nick Mathewson
453317b28c Fall back to sscanf if we have no other way to implement strtoll 2011-01-24 18:22:32 -05:00
Jardel Weyrich
666b096691 Detect and handle more allocation failures. 2011-01-07 13:03:31 -05:00
Nick Mathewson
22f4af6580 Remove end-of-line whitespace 2010-12-09 11:43:12 -05:00
Kevin Bowling
32390732d7 Fix snprintf related failures on IRIX. 2010-11-23 22:24:52 -05:00
Nick Mathewson
494186129f Use the US-English "canceled", not the UK "cancelled". 2010-11-19 12:08:29 -05:00
Nick Mathewson
a3245afec2 Fix win32 build in response to fixes from win64 build. 2010-11-01 14:23:33 -04:00
Nick Mathewson
f8095d64e2 Fix a typo in 7484df61c981fc33db2~ 2010-11-01 14:15:34 -04:00
Nick Mathewson
7484df61c9 Fix even more win64 warnings 2010-11-01 13:43:43 -04:00
Nick Mathewson
19c71e7454 Fix som event_warns that should have been event_warnx 2010-10-27 10:36:08 -04:00
Trond Norbye
f5ad31c186 Check return value for ioctlsocket on win32 2010-10-27 12:49:17 +02:00
Nick Mathewson
a8b7674cd5 Merge remote branch 'github/signed_compare' 2010-09-28 01:09:17 -04:00
Nick Mathewson
d49b5e3326 Do not search outside of the system directory for windows DLLs
Hardens against some attacks.
2010-09-27 15:45:34 -04:00
Nick Mathewson
9c8db0f804 Fix all warnings in the main codebase flagged by -Wsigned-compare
Remember, the code
   int is_less_than(int a, unsigned b) {
      return a < b;
   }
is buggy, since the C integer promotion rules basically turn it into
   int is_less_than(int a, unsigned b) {
      return ((unsigned)a) < b;
   }
and we really want something closer to
   int is_less_than(int a, unsigned b) {
      return a < 0 || ((unsigned)a) < b;
   }
.

Suggested by an example from Ralph Castain
2010-09-23 22:45:55 -04:00
Nick Mathewson
57d3413c55 Merge remote branch 'github/globals' 2010-09-08 11:39:24 -04:00
Nick Mathewson
e50c0fcc85 Use the _func() replacements for open, fstat, etc in evutil.c on win32
Remember that in a fit of ANSI C compliance, Microsoft decided to
screw portability by renaming basically all the functions in unistd.h to
get prefixed with an understore.

For some reason, mingw didn't seem to mind, but at least some people's
compilers did: see bug 3044490.
2010-09-02 13:13:28 -04:00
Nick Mathewson
1fdec20f8f Stop using global arrays to implement the EVUTIL_ctype functions
These apparently made libtool sad on win32, and the function call
overhead here should be negligable anyway.
2010-09-01 15:01:39 -04:00
Nick Mathewson
ec347b9225 Move event-config.h to include/event2
This change means that all required include files are in event2, and
all files not in event2/* are optional.
2010-08-06 20:21:27 -04:00
Nick Mathewson
57b30cd7cc Turn our socketpair() replacement into its own function
This patch splits the formerly windows-only case of evutil_socketpair()
into an (internal-use-only) function named evutil_ersatz_socketpair(), and
makes it build and work right on non-Windows hosts.

We need this for convenience to test sendfile on solaris, where socketpair
can't give you an AF_INET pair, and sendfile() won't work on AF_UNIX.
2010-08-06 13:01:32 -04:00
Nick Mathewson
7c2dea1615 Pass flags to fcntl(F_SETFL) and fcntl(F_SETFD) as int, not long
Everybody but Linux documents this as taking an int, and Linux is
very tolerant of getting an int instead.  If it weren't, everybody
doing fcntl(fd,F_SETFL,O_NONBLOCK) would break, since the glibc
headers define O_NONBLOCK as an int literal.
2010-07-13 11:09:47 -04:00
Pierre Phaneuf
0798dd1247 Close the file in evutil_read_file whether there's an error or not.
evutil_read_file would close the file if there was an error, but not if things went normally.
2010-05-27 22:37:09 -04:00
Nick Mathewson
47c5dfbea9 Remove some dead assignments 2010-05-18 17:28:51 -04:00
Nick Mathewson
8c3452bcb2 Correctly recognize .255 addresses as link-local when looking for interfaces 2010-05-18 13:55:32 -04:00
Nick Mathewson
c1cd32a156 Define _REENTRANT as needed on Solaris, elsewhere
It turns out that _REENTRANT isn't only needed to make certain
functions visible; we also need it to make pthreads work properly
some places (like Solaris, where forgetting _REENTRANT basically
means that all threads are sharing the same errno).  Fortunately,
our ACX_PTHREAD() configure macro already gives us a PTHREAD_CFLAG
variable, so all we have to do is use it.
2010-05-08 22:21:52 -04:00
Nick Mathewson
935e1504b1 Fix whitespace in evutil.c 2010-05-08 19:36:05 -04:00
Nick Mathewson
3557071698 Fix another nasty solaris getaddrinfo() behavior
Everybody else thinks that when you getaddrinfo() on an ip address
and don't specify the protocol and the socktype, it should give you
multiple answers , one for each protocol/socktype implementation.

OpenSolaris takes a funny view of RFC3493, and leaves the results set
to 0.

This patch post-processes the getaddrinfo() results for consistency.
2010-05-08 19:34:10 -04:00
Nick Mathewson
2cf2a286e4 Fix getaddrinfo with protocol unset on Solaris 9. Found by Dagobert Michelsen
Apparently when you call Solaris 9's getaddrinfo(), it likes to leave
ai_protocol unset in the result. This is no way to behave, if I'm
reading RFC3493 right.

This patch makes us check for a getaddrinfo() that's broken in this way,
and work around it by trying to infer socktype and protocol from one
another.

Partial bugfix for 2987542
2010-05-08 19:34:09 -04:00
Nick Mathewson
20fda296c5 Try /proc on Linux as entropy fallback; use sysctl as last resort
It turns out that the happy fun Linux kernel is deprecating sysctl,
and using sysctl to fetch entropy will spew messages in the kernel
logs.  Let's not do that.  Instead, let's call sysctl for our
entropy only when all other means fail.

Additionally, let's add another means, and try
/proc/sys/kernel/random/uuid if /dev/urandom fails.
2010-05-03 13:00:00 -04:00
Nick Mathewson
b1c795007f Make evdns logging threadsafe
The old logging code was littered with places where we stored messages in
static char[] fields.  This is fine in a single-threaded program, but if you
ever tried to log evdns messages from two threads at once, you'd hit a race.

This patch also refactors evdns's debug_ntop function into a more useful
evutil_sockaddr_port_format() function, with unit tests.
2010-04-23 14:42:25 -04:00
Sebastian Sjöberg
899c1dcc98 Replace EVUTIL_CLOSESOCKET macro with a function
The EVUTIL_CLOSESOCKET() macro required you to include unistd.h in your
source for POSIX.  We might as well turn it into a function: an extra
function call is going to be cheap in comparison with the system call.

We retain the EVUTIL_CLOSESOCKET() macro as an alias for the new
evutil_closesocket() function.

(commit message from email by Nick and Sebastian)
2010-04-14 15:42:57 -04:00
Christopher Davis
8f9e60c825 Always round up when there's a fractional number of msecs. 2010-04-09 19:16:09 -07:00
Christopher Davis
850c3ff232 Add evutil_tv_to_msec for safe conversion of timevals to milliseconds.
This is useful for backends that require their timeout values be in
milliseconds.
2010-03-31 23:38:34 -07:00
Nick Mathewson
cdd4c4905b Try to comment some of the event code more 2010-03-12 00:38:50 -05:00
Brodie Thiesfield
b677032ba2 Avoid errors in evutil.c when building with _UNICODE defined 2010-03-08 13:46:04 -05:00
Nick Mathewson
17efc1cdfa Update all our copyright notices to say "2010" 2010-03-04 01:38:48 -05:00
Nick Mathewson
57b7248823 Small cleanups on freebsd-connect-refused patch.
There should be no need to call be_socket_enable: that does an
event_add().  What we really want to do is event_active(), to make
sure that the writecb is executed.

Also, there was one "} if () {" that was missing an else.

I've noted that the return value for evutil_socket_connect() is
getting screwy, but since that isn't an exported function, we can fix
it whenever.
2010-02-27 22:27:13 -05:00
Niels Provos
7bc48bfd3a deal with connect() failing immediately 2010-02-27 18:59:06 -08:00
Nick Mathewson
4faeaea90e Clean up formatting: function/keyword spacing consistency.
- Keywords always have a space before a paren.  Functions never do.

- No more than 3 blank lines in a row.
2010-02-19 03:39:50 -05:00
Nick Mathewson
e5bbd40ad7 Clean up formatting: use tabs, not 8-spaces, to indent. 2010-02-18 17:44:09 -05:00
Nick Mathewson
d4de062efc Add an arc4random implementation for use by evdns
Previously, evdns was at the mercy of the user for providing a good
entropy source; without one, it would be vulnerable to various
active attacks.

This patch adds a port of OpenBSD's arc4random() calls to Libevent
[port by Chris Davis], and wraps it up a little bit so we can use it
more safely.
2010-02-11 12:53:32 -05:00