Skip to content

Commit 5edfe76

Browse files
committed
utils: validate sds port
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 05b7a16 commit 5edfe76

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
@@ -1256,6 +1256,7 @@ int flb_utils_url_split(const char *in_url, char **out_protocol,
12561256
int flb_utils_url_split_sds(const flb_sds_t in_url, flb_sds_t *out_protocol,
12571257
flb_sds_t *out_host, flb_sds_t *out_port, flb_sds_t *out_uri)
12581258
{
1259+
int i;
12591260
flb_sds_t protocol = NULL;
12601261
flb_sds_t host = NULL;
12611262
flb_sds_t port = NULL;
@@ -1337,10 +1338,21 @@ int flb_utils_url_split_sds(const flb_sds_t in_url, flb_sds_t *out_protocol,
13371338
flb_errno();
13381339
goto error;
13391340
}
1341+
13401342
if (!port) {
13411343
flb_errno();
13421344
goto error;
13431345
}
1346+
else {
1347+
/* check that port is a number */
1348+
for (i = 0; i < flb_sds_len(port); i++) {
1349+
if (!isdigit(port[i])) {
1350+
goto error;
1351+
}
1352+
}
1353+
1354+
}
1355+
13441356
if (!uri) {
13451357
flb_errno();
13461358
goto error;
@@ -1355,7 +1367,16 @@ int flb_utils_url_split_sds(const flb_sds_t in_url, flb_sds_t *out_protocol,
13551367

13561368
error:
13571369
if (protocol) {
1358-
flb_free(protocol);
1370+
flb_sds_destroy(protocol);
1371+
}
1372+
if (host) {
1373+
flb_sds_destroy(host);
1374+
}
1375+
if (port) {
1376+
flb_sds_destroy(port);
1377+
}
1378+
if (uri) {
1379+
flb_sds_destroy(uri);
13591380
}
13601381

13611382
return -1;

0 commit comments

Comments
 (0)