release: version 1.0.10 - Fix JSON serialization and remove unused fields
- FIX: Correct JSON string length parameters for query field (8→9) - FIX: Add null-termination after buffer reallocation in dynbuf_append - CHANGE: Remove unparsed_uri, fragment, and content_length fields - TEST: Update unit tests to match dynbuf_append fix Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
%global spec_version 1.0.9
|
||||
%global spec_version 1.0.10
|
||||
|
||||
Name: mod_reqin_log
|
||||
Version: %{spec_version}
|
||||
@ -37,6 +37,12 @@ install -m 644 %{_pkgroot}/%{_sysconfdir}/httpd/conf.d/mod_reqin_log.conf %{buil
|
||||
%doc %{_docdir}/%{name}
|
||||
|
||||
%changelog
|
||||
* Mon Mar 02 2026 Developer <dev@example.com> - 1.0.10
|
||||
- FIX: Correct JSON string length parameters for query and fragment fields
|
||||
- FIX: Add null-termination after buffer reallocation in dynbuf_append
|
||||
- CHANGE: Remove unparsed_uri, fragment, and content_length fields from JSON output
|
||||
- TEST: Update unit tests to match dynbuf_append fix
|
||||
|
||||
* Mon Mar 02 2026 Developer <dev@example.com> - 1.0.9
|
||||
- CHANGE: Remove req_id field from JSON output
|
||||
- FEATURE: Add query and fragment fields (URI components)
|
||||
|
||||
@ -214,6 +214,7 @@ static void dynbuf_append(dynbuf_t *db, const char *str, apr_size_t len)
|
||||
apr_size_t new_capacity = (db->len + len + 1) * 2;
|
||||
char *new_data = apr_palloc(db->pool, new_capacity);
|
||||
memcpy(new_data, db->data, db->len);
|
||||
new_data[db->len] = '\0';
|
||||
db->data = new_data;
|
||||
db->capacity = new_capacity;
|
||||
}
|
||||
@ -669,11 +670,7 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
const char *host;
|
||||
const char *http_version;
|
||||
const char *scheme;
|
||||
const char *unparsed_uri;
|
||||
const char *query;
|
||||
const char *fragment;
|
||||
const char *content_length_str;
|
||||
apr_int64_t content_length;
|
||||
|
||||
if (!r || !r->server || !r->pool || !r->connection) {
|
||||
return;
|
||||
@ -719,13 +716,6 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
scheme = "http";
|
||||
}
|
||||
|
||||
/* unparsed_uri (raw, unnormalized URI) */
|
||||
unparsed_uri = r->unparsed_uri ? r->unparsed_uri : "";
|
||||
/* Sanitize unparsed_uri to prevent oversized values */
|
||||
if (strlen(unparsed_uri) > 2048) {
|
||||
unparsed_uri = apr_pstrmemdup(pool, unparsed_uri, 2048);
|
||||
}
|
||||
|
||||
/* query (query string from parsed URI, e.g., ?foo=bar) */
|
||||
query = r->parsed_uri.query ? r->parsed_uri.query : "";
|
||||
/* Sanitize query to prevent oversized values */
|
||||
@ -733,26 +723,6 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
query = apr_pstrmemdup(pool, query, 2048);
|
||||
}
|
||||
|
||||
/* fragment (fragment from parsed URI, e.g., #section) */
|
||||
fragment = r->parsed_uri.fragment ? r->parsed_uri.fragment : "";
|
||||
/* Sanitize fragment to prevent oversized values */
|
||||
if (strlen(fragment) > 2048) {
|
||||
fragment = apr_pstrmemdup(pool, fragment, 2048);
|
||||
}
|
||||
|
||||
/* content_length (from Content-Length header) */
|
||||
content_length_str = apr_table_get(r->headers_in, "Content-Length");
|
||||
if (content_length_str != NULL) {
|
||||
char *endptr;
|
||||
errno = 0;
|
||||
content_length = strtoll(content_length_str, &endptr, 10);
|
||||
if (errno != 0 || endptr == content_length_str || *endptr != '\0' || content_length < 0) {
|
||||
content_length = 0;
|
||||
}
|
||||
} else {
|
||||
content_length = 0;
|
||||
}
|
||||
|
||||
dynbuf_init(&buf, pool, 4096);
|
||||
|
||||
dynbuf_append(&buf, "{", 1);
|
||||
@ -819,21 +789,11 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
append_json_string(&buf, path);
|
||||
dynbuf_append(&buf, "\",", 2);
|
||||
|
||||
/* unparsed_uri (raw, unnormalized URI) */
|
||||
dynbuf_append(&buf, "\"unparsed_uri\":\"", 16);
|
||||
append_json_string(&buf, unparsed_uri);
|
||||
dynbuf_append(&buf, "\",", 2);
|
||||
|
||||
/* query (query string without leading ?, e.g., foo=bar) */
|
||||
dynbuf_append(&buf, "\"query\":\"", 8);
|
||||
dynbuf_append(&buf, "\"query\":\"", 9);
|
||||
append_json_string(&buf, query);
|
||||
dynbuf_append(&buf, "\",", 2);
|
||||
|
||||
/* fragment (fragment without leading #, e.g., section) */
|
||||
dynbuf_append(&buf, "\"fragment\":\"", 11);
|
||||
append_json_string(&buf, fragment);
|
||||
dynbuf_append(&buf, "\"", 1);
|
||||
|
||||
/* host */
|
||||
dynbuf_append(&buf, ",\"host\":\"", 9);
|
||||
append_json_string(&buf, host);
|
||||
@ -852,14 +812,6 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
dynbuf_append(&buf, ka_buf, -1);
|
||||
}
|
||||
|
||||
/* content_length (from Content-Length header) */
|
||||
dynbuf_append(&buf, ",\"content_length\":", 18);
|
||||
{
|
||||
char cl_buf[32];
|
||||
snprintf(cl_buf, sizeof(cl_buf), "%" APR_INT64_T_FMT, content_length);
|
||||
dynbuf_append(&buf, cl_buf, -1);
|
||||
}
|
||||
|
||||
/* Check buffer size before adding headers to prevent memory exhaustion */
|
||||
if (buf.len >= MAX_JSON_SIZE) {
|
||||
if (SHOULD_LOG(srv_conf, REQIN_LOG_LEVEL_DEBUG)) {
|
||||
|
||||
@ -43,7 +43,8 @@ static void testbuf_append(testbuf_t *buf, const char *str, size_t len)
|
||||
if (buf->len + len + 1 > buf->cap) {
|
||||
size_t new_cap = (buf->len + len + 1) * 2;
|
||||
char *new_data = apr_palloc(buf->pool, new_cap);
|
||||
memcpy(new_data, buf->data, buf->len + 1);
|
||||
memcpy(new_data, buf->data, buf->len);
|
||||
new_data[buf->len] = '\0';
|
||||
buf->data = new_data;
|
||||
buf->cap = new_cap;
|
||||
}
|
||||
|
||||
@ -85,6 +85,7 @@ static void dynbuf_append(dynbuf_t *db, const char *str, apr_size_t len)
|
||||
apr_size_t new_capacity = (db->len + len + 1) * 2;
|
||||
char *new_data = apr_palloc(db->pool, new_capacity);
|
||||
memcpy(new_data, db->data, db->len);
|
||||
new_data[db->len] = '\0';
|
||||
db->data = new_data;
|
||||
db->capacity = new_capacity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user