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

Fix segmentation fault in kws_connect_ex #148

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions src/kws.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,6 @@ KS_DECLARE(ks_status_t) kws_connect_ex(kws_t **kwsP, ks_json_t *params, kws_flag
const char *ip = "127.0.0.1";
ks_port_t port = 443;
// char buf[50] = "";
struct hostent *he;
const char *url = ks_json_get_object_string(params, "url", NULL);
// const char *headers = ks_json_get_object_string(params, "headers", NULL);
const char *host = NULL;
Expand All @@ -1673,6 +1672,7 @@ KS_DECLARE(ks_status_t) kws_connect_ex(kws_t **kwsP, ks_json_t *params, kws_flag
char *p = NULL;
const char *client_data = NULL;
int destroy_ssl_ctx = 0;
ks_status_t status;

if (!url) {
ks_json_t *tmp;
Expand Down Expand Up @@ -1732,20 +1732,8 @@ KS_DECLARE(ks_status_t) kws_connect_ex(kws_t **kwsP, ks_json_t *params, kws_flag

if (!host || !path) return KS_STATUS_FAIL;

he = gethostbyname(host);

if (!he) {
ip = host;

if (strchr(ip, ':')) {
family = AF_INET6;
}

ks_addr_set(&addr, ip, port, family);
} else {
ks_addr_set_raw(&addr, he->h_addr, port, ((struct sockaddr_in *)he->h_addr)->sin_family);
// ip = ks_addr_get_host(&addr1);
}
status = ks_addr_getbyname(host, port, AF_UNSPEC, &addr);
if (status != KS_STATUS_SUCCESS) return status;

cl_sock = ks_socket_connect_ex(SOCK_STREAM, IPPROTO_TCP, &addr, timeout_ms);

Expand Down
Loading