Skip to content

Commit

Permalink
Expanding BASIC_CHECKS to prevent segfaults on invalid socket IDs (e.…
Browse files Browse the repository at this point in the history
…g., -1)
  • Loading branch information
Jack R. Dunaway committed Jan 9, 2015
1 parent 6a333ae commit d7fdfc3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@
CT_ASSERT (NN_MAX_SOCKETS <= 0x10000);

/* This check is performed at the beginning of each socket operation to make
sure that the library was initialised and the socket actually exists. */
sure that the library was initialised, the socket actually exists, and is
a valid socket index. */
#define NN_BASIC_CHECKS \
if (nn_slow (s < 0 || s > NN_MAX_SOCKETS)) {\
errno = EBADF;\
return -1;\
}\
if (nn_slow (!self.socks || !self.socks [s])) {\
errno = EBADF;\
return -1;\
Expand Down

0 comments on commit d7fdfc3

Please sign in to comment.