Skip to content

Commit

Permalink
Fix logic error bugs.
Browse files Browse the repository at this point in the history
scan-build result for socks5.c:256:

    Function call argument is an uninitialized value

nextstate can be undefined reply's addrtype field has unexpected value.
Fix by adding else case before to report error, drop client and return
from socks5_read_reply() function.

scan-build result for main.c:144, parser.c:193:

    Result of operation is garbage or undefined

If there is early error in main() in second FOREACH block, then
terminators array is not itialized before access in shutdown path.
Fix by moving memset() to precede this block.

gettoken() does not initialize copytype enum value, so can have a
garbage value at some point. Add else case to the chain of **iter tests
to report error and return from the function.
  • Loading branch information
przemoc committed Jan 27, 2011
1 parent c82e944 commit 39b2639
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;

event_init();
memset(terminators, 0, sizeof(terminators));

FOREACH(ss, subsystems) {
if ((*ss)->init) {
Expand All @@ -124,7 +125,6 @@ int main(int argc, char **argv)
}

assert(SIZEOF_ARRAY(exit_signals) == SIZEOF_ARRAY(terminators));
memset(terminators, 0, sizeof(terminators));
for (i = 0; i < SIZEOF_ARRAY(exit_signals); i++) {
signal_set(&terminators[i], exit_signals[i], terminate, NULL);
if (signal_add(&terminators[i], NULL) != 0) {
Expand Down
4 changes: 4 additions & 0 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ static char *gettoken(parser_context *context, char **iter)
copytype = gt_plainstr;
len = 2;
}
else {
parser_error(context, "unexpected char");
return NULL;
}

ret = malloc(len + 1);
if (!ret) {
Expand Down
5 changes: 5 additions & 0 deletions socks5.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ static void socks5_read_reply(struct bufferevent *buffev, redsocks_client *clien
len = sizeof(domain.size);
nextstate = socks5_skip_domain;
}
else {
redsocks_log_error(client, LOG_NOTICE, "Socks5 server reported unexpected address type...");
redsocks_drop_client(client);
return;
}

redsocks_write_helper(
buffev, client,
Expand Down

0 comments on commit 39b2639

Please sign in to comment.