fix: Sécuriser l’écriture socket et initialiser APR dans les tests
Co-authored-by: aider (openrouter/openai/gpt-5.3-codex) <aider@aider.chat>
This commit is contained in:
@ -28,6 +28,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#ifndef MSG_NOSIGNAL
|
||||||
|
#define MSG_NOSIGNAL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Maximum Unix socket path length (sun_path is typically 108 bytes) */
|
/* Maximum Unix socket path length (sun_path is typically 108 bytes) */
|
||||||
#define MAX_SOCKET_PATH_LEN (sizeof(((struct sockaddr_un *)0)->sun_path) - 1)
|
#define MAX_SOCKET_PATH_LEN (sizeof(((struct sockaddr_un *)0)->sun_path) - 1)
|
||||||
|
|
||||||
@ -513,8 +517,14 @@ static int write_to_socket(const char *data, apr_size_t len, server_rec *s,
|
|||||||
reqin_log_config_t *cfg, reqin_log_child_state_t *state)
|
reqin_log_config_t *cfg, reqin_log_child_state_t *state)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
apr_size_t total_written = 0;
|
ssize_t n;
|
||||||
apr_time_t error_interval = apr_time_from_sec(cfg->error_report_interval);
|
apr_time_t error_interval;
|
||||||
|
|
||||||
|
if (!cfg || !state || !s || !data || len == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_interval = apr_time_from_sec(cfg->error_report_interval);
|
||||||
|
|
||||||
FD_MUTEX_LOCK(state);
|
FD_MUTEX_LOCK(state);
|
||||||
|
|
||||||
@ -524,8 +534,7 @@ static int write_to_socket(const char *data, apr_size_t len, server_rec *s,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (total_written < len) {
|
n = send(fd, data, len, MSG_DONTWAIT | MSG_NOSIGNAL);
|
||||||
ssize_t n = write(fd, data + total_written, len - total_written);
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
int err = errno;
|
int err = errno;
|
||||||
apr_time_t now = apr_time_now();
|
apr_time_t now = apr_time_now();
|
||||||
@ -559,7 +568,12 @@ static int write_to_socket(const char *data, apr_size_t len, server_rec *s,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_written += (apr_size_t)n;
|
if ((apr_size_t)n < len) {
|
||||||
|
close(fd);
|
||||||
|
state->socket_fd = -1;
|
||||||
|
state->connect_failed = 1;
|
||||||
|
FD_MUTEX_UNLOCK(state);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_MUTEX_UNLOCK(state);
|
FD_MUTEX_UNLOCK(state);
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <apr_strings.h>
|
#include <apr_strings.h>
|
||||||
#include <apr_tables.h>
|
#include <apr_tables.h>
|
||||||
|
#include <apr_pools.h>
|
||||||
|
#include <apr_general.h>
|
||||||
|
|
||||||
/* Mock header truncation function */
|
/* Mock header truncation function */
|
||||||
static char *truncate_header_value(apr_pool_t *pool, const char *value, int max_len)
|
static char *truncate_header_value(apr_pool_t *pool, const char *value, int max_len)
|
||||||
@ -191,6 +193,19 @@ static void test_header_value_unicode(void **state)
|
|||||||
apr_pool_destroy(pool);
|
apr_pool_destroy(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int group_setup(void **state)
|
||||||
|
{
|
||||||
|
(void)state;
|
||||||
|
return apr_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int group_teardown(void **state)
|
||||||
|
{
|
||||||
|
(void)state;
|
||||||
|
apr_terminate();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
@ -207,5 +222,5 @@ int main(void)
|
|||||||
cmocka_unit_test(test_header_value_unicode),
|
cmocka_unit_test(test_header_value_unicode),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
return cmocka_run_group_tests(tests, group_setup, group_teardown);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#include <apr_strings.h>
|
#include <apr_strings.h>
|
||||||
#include <apr_time.h>
|
#include <apr_time.h>
|
||||||
#include <apr_lib.h>
|
#include <apr_lib.h>
|
||||||
|
#include <apr_general.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *data;
|
char *data;
|
||||||
@ -235,6 +236,19 @@ static void test_json_escape_user_agent(void **state)
|
|||||||
apr_pool_destroy(pool);
|
apr_pool_destroy(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int group_setup(void **state)
|
||||||
|
{
|
||||||
|
(void)state;
|
||||||
|
return apr_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int group_teardown(void **state)
|
||||||
|
{
|
||||||
|
(void)state;
|
||||||
|
apr_terminate();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
@ -248,5 +262,5 @@ int main(void)
|
|||||||
cmocka_unit_test(test_json_escape_user_agent),
|
cmocka_unit_test(test_json_escape_user_agent),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
return cmocka_run_group_tests(tests, group_setup, group_teardown);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user