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

Fixed some issues found by tests with enabled UndefinedBehaviorSanitizer #1109

Merged
merged 7 commits into from
Mar 11, 2024
5 changes: 3 additions & 2 deletions src/nxt_http_js.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ static njs_int_t
nxt_http_js_ext_get_args(njs_vm_t *vm, njs_object_prop_t *prop,
njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
{
u_char *start;
njs_int_t ret;
njs_value_t *args;
njs_opaque_value_t val;
Expand All @@ -175,8 +176,8 @@ nxt_http_js_ext_get_args(njs_vm_t *vm, njs_object_prop_t *prop,

args = njs_value_arg(&val);

ret = njs_vm_query_string_parse(vm, r->args->start,
r->args->start + r->args->length, args);
start = (r->args->start != NULL) ? r->args->start : (u_char *) "";
ret = njs_vm_query_string_parse(vm, start, start + r->args->length, args);

if (ret == NJS_ERROR) {
return NJS_ERROR;
ac000 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
6 changes: 6 additions & 0 deletions src/nxt_http_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ nxt_http_arguments_parse(nxt_http_request_t *r)
return NULL;
}

if (nxt_slow_path(r->args->start == NULL)) {
goto end;
}

hash = NXT_HTTP_FIELD_HASH_INIT;
name = NULL;
name_length = 0;
ac000 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -1026,6 +1030,8 @@ nxt_http_arguments_parse(nxt_http_request_t *r)
}
}

end:

r->arguments = args;

return args;
Expand Down
4 changes: 4 additions & 0 deletions src/nxt_http_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,10 @@ nxt_http_route_pattern(nxt_http_request_t *r, nxt_http_route_pattern_t *pattern,
return 0;
}

if (nxt_slow_path(start == NULL)) {
return 1;
}

nxt_assert(pattern->u.pattern_slices != NULL);

pattern_slices = pattern->u.pattern_slices;
ac000 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
6 changes: 6 additions & 0 deletions src/nxt_port_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ nxt_port_mmap_get(nxt_task_t *task, nxt_port_mmaps_t *mmaps, nxt_chunk_id_t *c,

nxt_thread_mutex_lock(&mmaps->mutex);

if (nxt_slow_path(mmaps->elts == NULL)) {
goto end;
}

end_port_mmap = mmaps->elts + mmaps->size;

for (port_mmap = mmaps->elts;
ac000 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -500,6 +504,8 @@ nxt_port_mmap_get(nxt_task_t *task, nxt_port_mmaps_t *mmaps, nxt_chunk_id_t *c,

/* TODO introduce port_mmap limit and release wait. */

end:

*c = 0;
mmap_handler = nxt_port_new_port_mmap(task, mmaps, tracking, n);

Expand Down
8 changes: 4 additions & 4 deletions src/nxt_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ nxt_random(nxt_random_t *r)
nxt_random_stir(r);
}

val = nxt_random_byte(r) << 24;
val |= nxt_random_byte(r) << 16;
val |= nxt_random_byte(r) << 8;
val |= nxt_random_byte(r);
val = (uint32_t) nxt_random_byte(r) << 24;
val |= (uint32_t) nxt_random_byte(r) << 16;
val |= (uint32_t) nxt_random_byte(r) << 8;
val |= (uint32_t) nxt_random_byte(r);

return val;
}
Expand Down
8 changes: 7 additions & 1 deletion src/nxt_unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1483,9 +1483,9 @@ nxt_unit_request_check_response_port(nxt_unit_request_info_t *req,
pthread_mutex_lock(&lib->mutex);

port = nxt_unit_port_hash_find(&lib->ports, port_id, 0);
port_impl = nxt_container_of(port, nxt_unit_port_impl_t, port);

if (nxt_fast_path(port != NULL)) {
port_impl = nxt_container_of(port, nxt_unit_port_impl_t, port);
req->response_port = port;

if (nxt_fast_path(port_impl->ready)) {
Expand Down Expand Up @@ -3502,6 +3502,10 @@ nxt_unit_mmap_get(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port,

pthread_mutex_lock(&lib->outgoing.mutex);

if (nxt_slow_path(lib->outgoing.elts == NULL)) {
goto skip;
}

retry:

outgoing_size = lib->outgoing.size;
ac000 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -3598,6 +3602,8 @@ nxt_unit_mmap_get(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port,
goto retry;
}

skip:

*c = 0;
hdr = nxt_unit_new_mmap(ctx, port, *n);

Expand Down
Loading