Skip to content

Commit

Permalink
Add warning if context length is exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
jajik committed Jun 7, 2024
1 parent 34dc011 commit 1d364ed
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions native/mod_manager/mod_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,53 +794,63 @@ static void read_remove_context(mem_t *mem, contextinfo_t *context)
}
}

static apr_status_t insert_update_context_guard(server_rec *s, mem_t *mem, contextinfo_t *info, char *context,
int status)
{
int len = strlen(context);
if (len > CONTEXTSZ) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
"process_config: received context %s is too long (trimmed to 255 characters)", context);
}

info->id = 0;
strncpy(info->context, context, CONTEXTSZ);
info->context[CONTEXTSZ] = '\0';
if (status == REMOVE) {
read_remove_context(mem, info);
return APR_SUCCESS;
}

return insert_update_context(mem, info);
}

/**
* Insert the context from Context information
* Note:
* 1 - if status is REMOVE remove_context will be called
* 2 - return codes of REMOVE are ignored (always success)
*/
static apr_status_t insert_update_contexts(mem_t *mem, char *str, int node, int vhost, int status)
static apr_status_t insert_update_contexts(server_rec *s, mem_t *mem, char *str, int node, int vhost, int status)
{
char *ptr = str;
char *previous = str;
apr_status_t ret = APR_SUCCESS;
contextinfo_t info;
char empty[2] = {'/', '\0'};

char root[] = "/";
if (ptr == NULL) {
ptr = root;
previous = root;
}

info.node = node;
info.vhost = vhost;
info.status = status;
if (ptr == NULL) {
ptr = empty;
previous = ptr;
}

while (*ptr) {
if (*ptr == ',') {
*ptr = '\0';
info.id = 0;
strncpy(info.context, previous, sizeof(info.context));
if (status != REMOVE) {
ret = insert_update_context(mem, &info);
if (ret != APR_SUCCESS) {
return ret;
}
} else {
read_remove_context(mem, &info);
ret = insert_update_context_guard(s, mem, &info, previous, status);
if (ret != APR_SUCCESS) {
return ret;
}

previous = ptr + 1;
}
ptr++;
}
info.id = 0;
strncpy(info.context, previous, sizeof(info.context));
if (status != REMOVE) {
ret = insert_update_context(mem, &info);
} else {
read_remove_context(mem, &info);
}
return ret;

return insert_update_context_guard(s, mem, &info, previous, status);
}

/**
Expand Down Expand Up @@ -1516,7 +1526,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
loc_unlock_nodes();
return apr_psprintf(r->pool, MHOSTUI, nodeinfo.mess.JVMRoute);
}
if (insert_update_contexts(contextstatsmem, phost->context, id, vid, STOPPED) != APR_SUCCESS) {
if (insert_update_contexts(r->server, contextstatsmem, phost->context, id, vid, STOPPED) != APR_SUCCESS) {
loc_unlock_nodes();
return apr_psprintf(r->pool, MCONTUI, nodeinfo.mess.JVMRoute);
}
Expand Down Expand Up @@ -2193,7 +2203,8 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
}

/* Now update each context from Context: part */
if (insert_update_contexts(contextstatsmem, vhost->context, node->mess.id, host->vhost, status) != APR_SUCCESS) {
if (insert_update_contexts(r->server, contextstatsmem, vhost->context, node->mess.id, host->vhost, status) !=
APR_SUCCESS) {
loc_unlock_nodes();
*errtype = TYPEMEM;
return apr_psprintf(r->pool, MCONTUI, node->mess.JVMRoute);
Expand Down Expand Up @@ -2756,9 +2767,8 @@ static void print_contexts(request_rec *r, int reduce_display, int allow_cmd, in
if (ou->node != node || ou->vhost != host) {
continue;
}
ap_rprintf(r, "%.*s, Status: %s Request: %d ", CONTEXTSZ,
mc_escape_html(r->pool, ou->context, CONTEXTSZ), context_status_to_string(ou->status),
ou->nbrequests);
ap_rprintf(r, "%.*s, Status: %s Request: %d ", CONTEXTSZ, mc_escape_html(r->pool, ou->context, CONTEXTSZ),
context_status_to_string(ou->status), ou->nbrequests);
if (allow_cmd) {
print_context_command(r, ou, Alias, JVMRoute);
}
Expand Down

0 comments on commit 1d364ed

Please sign in to comment.