Skip to content

Commit f0e6f2b

Browse files
committed
utils: validate sds port
Signed-off-by: Eduardo Silva <[email protected]>
1 parent d7a7668 commit f0e6f2b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/flb_utils.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ int flb_utils_url_split(const char *in_url, char **out_protocol,
11381138
int flb_utils_url_split_sds(const flb_sds_t in_url, flb_sds_t *out_protocol,
11391139
flb_sds_t *out_host, flb_sds_t *out_port, flb_sds_t *out_uri)
11401140
{
1141+
int i;
11411142
flb_sds_t protocol = NULL;
11421143
flb_sds_t host = NULL;
11431144
flb_sds_t port = NULL;
@@ -1219,10 +1220,21 @@ int flb_utils_url_split_sds(const flb_sds_t in_url, flb_sds_t *out_protocol,
12191220
flb_errno();
12201221
goto error;
12211222
}
1223+
12221224
if (!port) {
12231225
flb_errno();
12241226
goto error;
12251227
}
1228+
else {
1229+
/* check that port is a number */
1230+
for (i = 0; i < flb_sds_len(port); i++) {
1231+
if (!isdigit(port[i])) {
1232+
goto error;
1233+
}
1234+
}
1235+
1236+
}
1237+
12261238
if (!uri) {
12271239
flb_errno();
12281240
goto error;
@@ -1237,7 +1249,16 @@ int flb_utils_url_split_sds(const flb_sds_t in_url, flb_sds_t *out_protocol,
12371249

12381250
error:
12391251
if (protocol) {
1240-
flb_free(protocol);
1252+
flb_sds_destroy(protocol);
1253+
}
1254+
if (host) {
1255+
flb_sds_destroy(host);
1256+
}
1257+
if (port) {
1258+
flb_sds_destroy(port);
1259+
}
1260+
if (uri) {
1261+
flb_sds_destroy(uri);
12411262
}
12421263

12431264
return -1;

0 commit comments

Comments
 (0)