Skip to content
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
31 changes: 30 additions & 1 deletion src/app/shared/commands/monitor/monitor.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "../../../../util/fd_util.h"
/* TODO: Layering violation */
#include "../../../shared_dev/commands/bench/bench.h"

Expand All @@ -22,6 +21,8 @@
#include <termios.h>
#include "generated/monitor_seccomp.h"

extern action_t * ACTIONS[];

void
monitor_cmd_args( int * pargc,
char *** pargv,
Expand All @@ -35,6 +36,12 @@ monitor_cmd_args( int * pargc,
args->monitor.with_bench = fd_env_strip_cmdline_contains( pargc, pargv, "--bench" );
args->monitor.with_sankey = fd_env_strip_cmdline_contains( pargc, pargv, "--sankey" );

char const * topo_name = fd_env_strip_cmdline_cstr( pargc, pargv, "--topo", NULL, "" );

ulong topo_name_len = strlen( topo_name );
if( FD_UNLIKELY( topo_name_len > sizeof(args->monitor.topo)-1 ) ) FD_LOG_ERR(( "Unknown --topo %s", topo_name ));
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length check for --topo reports "Unknown --topo", but the actual failure mode here is that the provided string is too long for args->monitor.topo. This is misleading for users and also logs the full (potentially very large) input string. Consider changing the message to something like "--topo too long (max N)" and/or truncating the logged value to the buffer size.

Suggested change
if( FD_UNLIKELY( topo_name_len > sizeof(args->monitor.topo)-1 ) ) FD_LOG_ERR(( "Unknown --topo %s", topo_name ));
ulong max_topo_len = sizeof(args->monitor.topo) - 1UL;
if( FD_UNLIKELY( topo_name_len > max_topo_len ) )
FD_LOG_ERR(( "--topo too long (max %lu chars)", max_topo_len ));

Copilot uses AI. Check for mistakes.
fd_cstr_fini( fd_cstr_append_text( fd_cstr_init( args->monitor.topo ), topo_name, topo_name_len ) );

if( FD_UNLIKELY( args->monitor.dt_min<0L ) ) FD_LOG_ERR(( "--dt-min should be positive" ));
if( FD_UNLIKELY( args->monitor.dt_max<args->monitor.dt_min ) ) FD_LOG_ERR(( "--dt-max should be at least --dt-min" ));
if( FD_UNLIKELY( args->monitor.duration<0L ) ) FD_LOG_ERR(( "--duration should be non-negative" ));
Expand Down Expand Up @@ -498,9 +505,31 @@ signal1( int sig ) {
exit( 0 ); /* gracefully exit */
}

static void
reconstruct_topo( config_t * config,
char const * topo_name ) {
if( !topo_name[0] ) return; /* keep default action topo */

action_t const * selected = NULL;
for( action_t ** a=ACTIONS; *a; a++ ) {
action_t const * action = *a;
if( 0==strcmp( action->name, topo_name ) ) {
selected = action;
break;
}
}

if( !selected ) FD_LOG_ERR(( "Unknown --topo %s", topo_name ));
if( !selected->topo ) FD_LOG_ERR(( "Cannot recover topology for --topo %s", topo_name ));

selected->topo( config );
}

void
monitor_cmd_fn( args_t * args,
config_t * config ) {
reconstruct_topo( config, args->monitor.topo );

if( FD_UNLIKELY( args->monitor.with_bench ) ) {
add_bench_topo( &config->topo,
config->development.bench.affinity,
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/fd_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ union fdctl_args {
} run1;

struct {
char topo[ 64 ];
long dt_min;
long dt_max;
long duration;
Expand Down
Loading