Skip to content

Commit 77da647

Browse files
riptlripatel-fd
authored andcommitted
Fix uninit stack exposure in genesis_create
1 parent dcae0c9 commit 77da647

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/app/shared_dev/commands/configure/genesis.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,20 @@ create_genesis( config_t const * config,
125125
uchar const * identity_pubkey_ = fd_keyload_load( config->paths.identity_key, 1 );
126126
if( FD_UNLIKELY( !identity_pubkey_ ) ) FD_LOG_ERR(( "Failed to load identity key" ));
127127
memcpy( options->identity_pubkey.key, identity_pubkey_, 32 );
128+
fd_keyload_unload( identity_pubkey_, 1 );
128129

129130
char file_path[ PATH_MAX ];
130131
FD_TEST( fd_cstr_printf_check( file_path, PATH_MAX, NULL, "%s/faucet.json", config->paths.base ) );
131132
uchar const * faucet_pubkey_ = fd_keyload_load( file_path, 1 );
132133
if( FD_UNLIKELY( !faucet_pubkey_ ) ) FD_LOG_ERR(( "Failed to load faucet key" ));
133134
memcpy( options->faucet_pubkey.key, faucet_pubkey_, 32 );
135+
fd_keyload_unload( faucet_pubkey_, 1 );
134136

135137
FD_TEST( fd_cstr_printf_check( file_path, PATH_MAX, NULL, "%s/stake-account.json", config->paths.base ) );
136138
uchar const * stake_pubkey_ = fd_keyload_load( file_path, 1 );
137139
if( FD_UNLIKELY( !stake_pubkey_ ) ) FD_LOG_ERR(( "Failed to load stake account key" ));
138140
memcpy( options->stake_pubkey.key, stake_pubkey_, 32 );
141+
fd_keyload_unload( stake_pubkey_, 1 );
139142

140143
if( !strcmp( config->paths.vote_account, "" ) ) {
141144
FD_TEST( fd_cstr_printf_check( file_path, PATH_MAX, NULL, "%s/vote-account.json", config->paths.base ) );
@@ -146,7 +149,7 @@ create_genesis( config_t const * config,
146149
uchar const * vote_pubkey_ = fd_keyload_load( file_path, 1 );
147150
if( FD_UNLIKELY( !vote_pubkey_ ) ) FD_LOG_ERR(( "Failed to load vote account key" ));
148151
memcpy( options->vote_pubkey.key, vote_pubkey_, 32 );
149-
152+
fd_keyload_unload( vote_pubkey_, 1 );
150153

151154
options->creation_time = (ulong)fd_log_wallclock() / (ulong)1e9;
152155
options->faucet_balance = 500000000000000000UL;
@@ -209,11 +212,6 @@ create_genesis( config_t const * config,
209212

210213
fd_scratch_detach( NULL );
211214

212-
fd_keyload_unload( identity_pubkey_, 1 );
213-
fd_keyload_unload( faucet_pubkey_, 1 );
214-
fd_keyload_unload( stake_pubkey_, 1 );
215-
fd_keyload_unload( vote_pubkey_, 1 );
216-
217215
return blob_sz;
218216
}
219217

src/flamenco/genesis/fd_genesis_create.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ genesis_create( void * buf,
153153

154154
ulong const stake_account_index = genesis->accounts_len++;
155155

156-
uchar stake_data[ FD_STAKE_STATE_V2_SZ ];
156+
uchar stake_data[ FD_STAKE_STATE_V2_SZ ] = {0};
157157

158158
ulong stake_state_min_bal = fd_rent_exempt_minimum_balance( &genesis->rent, FD_STAKE_STATE_V2_SZ );
159159
ulong vote_min_bal = fd_rent_exempt_minimum_balance( &genesis->rent, FD_VOTE_STATE_V3_SZ );

src/flamenco/types/fd_bincode.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,13 @@ static inline int
186186
fd_bincode_bytes_encode( uchar const * self,
187187
ulong len,
188188
fd_bincode_encode_ctx_t * ctx ) {
189-
uchar *ptr = (uchar *) ctx->data;
190-
if ( FD_UNLIKELY((void *) (ptr + len) > ctx->dataend ) )
189+
fd_msan_check( self, len );
190+
191+
uchar * ptr = (uchar *)ctx->data;
192+
if( FD_UNLIKELY( (void *)( ptr+len ) > ctx->dataend ) )
191193
return FD_BINCODE_ERR_OVERFLOW;
192194

193-
fd_memcpy(ptr, self, len);
195+
fd_memcpy( ptr, self, len );
194196
ctx->data = ptr + len;
195197

196198
return FD_BINCODE_SUCCESS;

0 commit comments

Comments
 (0)