Skip to content

Commit

Permalink
Check eeach element for spaces
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Sep 6, 2023
1 parent c7a7e66 commit b9a5187
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions src/api/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,44 +319,49 @@ static int api_list_write(struct ftl_conn *api,
{
// Test validity of this regex
regexData regex = { 0 };
if(row.item != NULL)
cJSON *it = NULL;
cJSON_ArrayForEach(it, row.items)
{
// A single regex
okay = compile_regex(row.item, &regex, &regex_msg);
}
else
{
cJSON *it = NULL;
cJSON_ArrayForEach(it, row.items)
// If any element isn't a string, break early
if(!cJSON_IsString(it))
{
// If any element isn't a string, break early
if(!cJSON_IsString(it))
{
okay = false;
break;
}
okay = false;
break;
}

// Check every array element for its validity
okay = compile_regex(row.item, &regex, &regex_msg);
// Check every array element for its validity
okay = compile_regex(row.item, &regex, &regex_msg);

// Fail fast if any regex in the passed array is invalid
if(!okay)
break;
}
// TODO: The regex needs to be freed here

// Fail fast if any regex in the passed array is invalid
if(!okay)
break;
}
}
else if(!spaces_allowed)
{
// Check validity: Spaces are not allowed in any domain/URL
if(strchr(row.item, ' ') != NULL ||
strchr(row.item, '\t') != NULL ||
strchr(row.item, '\n') != NULL)
cJSON *it = NULL;
cJSON_ArrayForEach(it, row.items)
{
cJSON_free(row.items);
return send_json_error(api, 400, // 400 Bad Request
"bad_request",
"Spaces, newlines and tabs are not allowed in domains and URLs",
row.item);
// If any element isn't a string, break early
if(!cJSON_IsString(it))
{
okay = false;
break;
}

// Check validity: Spaces are not allowed in any domain/URL
if(strchr(it->valuestring, ' ') != NULL ||
strchr(it->valuestring, '\t') != NULL ||
strchr(it->valuestring, '\n') != NULL)
{
cJSON_free(row.items);
return send_json_error(api, 400, // 400 Bad Request
"bad_request",
"Spaces, newlines and tabs are not allowed in domains and URLs",
it->valuestring);
}
}
}

Expand Down

0 comments on commit b9a5187

Please sign in to comment.