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 crash when empty parameters in request #80

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pipeline {
PUBLIC_KEY = credentials('EPITECH_SSH_PUBKEY')
GHCR_TOKEN = credentials('github-packages-token')
IMAGE_NAME = 'epitech-mirroring/rountable-server'
IMAGE_VERSION = '1.02.8'
IMAGE_VERSION = '1.02.9'
MIRROR_URL = '[email protected]:EpitechPromo2027/B-NWP-400-NAN-4-1-myteams-marius.pain.git'
}
stages {
Expand Down
9 changes: 6 additions & 3 deletions common/network/src/dto/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ static char *parse_param(request_t *req, char *param)
regex_t regex;
regmatch_t matches[3];

regcomp(&regex, "([^=]+)=([^&]+)", REG_EXTENDED);
regcomp(&regex, "([^=]+)=?([^&]+)?", REG_EXTENDED);
if (regexec(&regex, param, 3, matches, 0) == 0) {
key = strndup(param + matches[1].rm_so,
matches[1].rm_eo - matches[1].rm_so);
value = strndup(param + matches[2].rm_so,
matches[2].rm_eo - matches[2].rm_so);
if (matches[2].rm_so != -1)
value = strndup(param + matches[2].rm_so,
matches[2].rm_eo - matches[2].rm_so);
if (value == NULL)
value = strdup("");
}
regfree(&regex);
request_add_param(req, key, value);
Expand Down
2 changes: 2 additions & 0 deletions server/src/clients/composables.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ roundtable_client_instance_t *get_instance_from_header(
if (header == NULL)
return NULL;
uuid_str = strndup(header + strlen("Bearer "), 32);
if (strlen(header) < strlen("Bearer ") + 32 + 2)
return NULL;
instance_str = header + strlen("Bearer ") + 32 + 1;
instance = get_instance_from_strings(server, uuid_str, instance_str);
free(uuid_str);
Expand Down
8 changes: 4 additions & 4 deletions server/src/routes/teams/channels/threads/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static response_t create_thread_response(roundtable_channel_t *channel,
}

static response_t validate_request(request_t *req, roundtable_server_t *srv,
roundtable_client_t *client, json_object_t *body)
roundtable_client_instance_t *client, json_object_t *body)
{
roundtable_team_t *team = get_team_from_json(srv, body, "team_uuid");
roundtable_channel_t *channel = NULL;
Expand All @@ -80,13 +80,13 @@ static response_t validate_request(request_t *req, roundtable_server_t *srv,
return create_error(401, "Unauthorized", "Invalid 'Authorization'");
if (!team)
return create_error(404, "Team not found", "Team not found");
if (!roundtable_team_has_subscriber(team, client))
if (!roundtable_team_has_subscriber(team, client->client))
return create_error(403, "Forbidden", "Client not a subscriber");
channel = get_channel_from_json(team, body,
"channel_uuid");
if (!channel)
return create_error(404, "Channel not found", "Channel not found");
return create_thread_response(channel, body, client);
return create_thread_response(channel, body, client->client);
}

response_t create_thread_route(request_t *request, void *data)
Expand All @@ -100,5 +100,5 @@ response_t create_thread_route(request_t *request, void *data)
return create_error(405, "Method not allowed", "Only POST");
if (!body || !body_is_valid(body))
return create_error(400, "Invalid body", get_missing_key(body));
return validate_request(request, server, instance->client, body);
return validate_request(request, server, instance, body);
}