-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Makes sure that proxy_auth is properly disposed #975
Conversation
ncat/ncat_connect.c
Outdated
@@ -695,21 +695,18 @@ static int do_proxy_socks5(void) | |||
|
|||
if (send(sd, (char *) &socks5msg, len, 0) < 0) { | |||
loguser("Error: proxy request: %s.\n", socket_strerror(socket_errno())); | |||
close(sd); | |||
return -1; | |||
goto error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the goto error;
statements are indented by tabs whereas the surrounding code uses spaces for indentation.
…ction fails. In case of error in proxy connection initialization proxy_auth pointer goes out of scope and memory leak reported by static analizer tool. While this is not critical because of application exit the fix is trivial.
Fixed (in amended commit) |
ncat/ncat_connect.c
Outdated
} | ||
|
||
return(sd); | ||
error: | ||
if (proxy_auth != NULL) | ||
free(proxy_auth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should free(proxy_auth)
also when no error occurs. This is not a problem introduced by your patch but still worth fixing.
ncat/ncat_connect.c
Outdated
@@ -788,6 +788,8 @@ static int do_proxy_socks5(void) | |||
goto error; | |||
} | |||
|
|||
free(proxy_auth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause a double free() if you jump to error:
from now on. Either put this bellow all the gotos, or put proxy_auth = NULL;
immediately after the first free().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Sorry. fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I see the issue and the fix makes sense but there is some other potentially suspect code in the vicinity so we might end up resolving it differently. Thank you for the note. |
Resolved in r37005 (6e83dc6) |
In case of error in proxy connection initialization proxy_auth pointer
goes out of scope and memory leak reported by static analizer tool.
While this is not critical because of application exit the fix is trivial.