Skip to content
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

Resolve problems connections coming in via SOCKS #92

Merged
merged 1 commit into from
Dec 28, 2023

Conversation

jschwartzenberg
Copy link
Collaborator

I was running into issues with connections that were reaching CNTLM via SOCKS. First of all it would try to use a proxy server whereas according to the PAC file there would be a direct connection. It seems that specifying / as the URL was not what the rest of the code was expecting. I saw that other code was passing the hostname or IP address instead plus the port number and the hostname or IP address without a port number. Once I changed that,, connections were made correctly directly.

I also saw problems due to the incomplete data1 structure after the code was passing through prepare_http_connect, so I added the hostname and port number to it. This can result in a segfault later on as the data is expected to be there.

With these fixes in place CNTLM is not crashing anymore and handling SOCKS connections without problems. I guess the code is not perfect though, so I'd be happy to get any feedback that would help to improve things :)

@fralken
Copy link
Collaborator

fralken commented Dec 23, 2023

Hello @jschwartzenberg this is a good catch. The code could be even simplified a bit, and I also suggest to use "hostname" instead of "thost_noport" (I know that it can contain an ip address rather than a real hostname) just to be consistent with other parts of the codebase. Also, a free is missing after strdup. I comment directly in the code diff.

forward.c Outdated Show resolved Hide resolved
forward.c Outdated Show resolved Hide resolved
main.c Outdated Show resolved Hide resolved
main.c Outdated Show resolved Hide resolved
@jschwartzenberg
Copy link
Collaborator Author

Hi @fralken thank you so much for the feedback!! I was already testing with the frees that Sonar pointed me to, so I just pushed those as my tests were successful. I will work on the points you made and do another push!

@jschwartzenberg jschwartzenberg force-pushed the fix-socks-proxying branch 2 times, most recently from df3a393 to 91a5076 Compare December 27, 2023 16:04
@fralken
Copy link
Collaborator

fralken commented Dec 27, 2023

That's great! I just added a comment on the main.c changes, because there is a case when hostname is freed without being allocated (some checks fail because of this).

main.c Outdated Show resolved Hide resolved
Copy link

@fralken
Copy link
Collaborator

fralken commented Dec 28, 2023

Now I guess it's ok. All quality checks pass (only DeepSource fails but for issues not related to this PR). Thanks for testing the Socks connection.

@fralken fralken merged commit a750e27 into versat:master Dec 28, 2023
10 checks passed
@jschwartzenberg jschwartzenberg changed the title Resolve problems connectings coming in via SOCKS Resolve problems connections coming in via SOCKS Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants