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

upstream: Improve error message for misconfigured HTTP_PROXY variable #9328

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/flb_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ struct flb_upstream *flb_upstream_create(struct flb_config *config,
&proxy_username, &proxy_password,
&proxy_host, &proxy_port);
if (ret == -1) {
flb_errno();
flb_free(u);
return NULL;
}
Expand Down
11 changes: 7 additions & 4 deletions src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ static inline void encoded_to_buf(char *out, const char *in, int len)

/*
* Write string pointed by 'str' to the destination buffer 'buf'. It's make sure
* to escape sepecial characters and convert utf-8 byte characters to string
* to escape special characters and convert utf-8 byte characters to string
* representation.
*/
int flb_utils_write_str(char *buf, int *off, size_t size,
Expand Down Expand Up @@ -1128,7 +1128,7 @@ int flb_utils_url_split(const char *in_url, char **out_protocol,

/*
* flb_utils_proxy_url_split parses a proxy's information from a http_proxy URL.
* The URL is in the form like `http://username:[email protected]:8080`.
* The URL is in the form like `http://[username:password@]myproxy.com:8080`.
* Note: currently only HTTP is supported.
*/
int flb_utils_proxy_url_split(const char *in_url, char **out_protocol,
Expand All @@ -1147,9 +1147,11 @@ int flb_utils_proxy_url_split(const char *in_url, char **out_protocol,
/* Parse protocol */
proto_sep = strstr(in_url, "://");
if (!proto_sep) {
flb_error("HTTP_PROXY variable must be set in the form of 'http://[username:password@]host:port'");
return -1;
}
if (proto_sep == in_url) {
flb_error("HTTP_PROXY variable must be set in the form of 'http://[username:password@]host:port'");
return -1;
}

Expand All @@ -1160,17 +1162,18 @@ int flb_utils_proxy_url_split(const char *in_url, char **out_protocol,
}
/* Only HTTP proxy is supported for now. */
if (strcmp(protocol, "http") != 0) {
flb_error("only HTTP proxy is supported.");
flb_free(protocol);
return -1;
}

/* Advance position after protocol */
proto_sep += 3;

/* Seperate `username:password` and `host:port` */
/* Separate `username:password` and `host:port` */
at_sep = strrchr(proto_sep, '@');
if (at_sep) {
/* Parse username:passwrod part. */
/* Parse username:password part. */
tmp = strchr(proto_sep, ':');
if (!tmp) {
flb_free(protocol);
Expand Down
Loading