Skip to content

Commit 1781a01

Browse files
runtime: initial patches for types fuzzer
1 parent c457fae commit 1781a01

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

src/flamenco/runtime/tests/harness/fd_exec_sol_compat.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,6 @@ sol_compat_type_execute_v1( uchar * out,
840840
ulong in_sz ) {
841841
// Setup
842842
fd_runtime_fuzz_runner_t * runner = sol_compat_setup_runner();
843-
844843
// Decode context
845844
fd_exec_test_type_context_t input[1] = {0};
846845
void * res = sol_compat_decode( &input, in, in_sz, &fd_exec_test_type_context_t_msg );
@@ -854,7 +853,6 @@ sol_compat_type_execute_v1( uchar * out,
854853

855854
void * output = NULL;
856855
sol_compat_execute_wrapper( runner, input, &output, fd_runtime_fuzz_type_run );
857-
858856
if( output ) {
859857
ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_type_effects_t_msg );
860858
}

src/flamenco/runtime/tests/harness/fd_types_harness.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ custom_serializer_walk( void * _self,
167167
break;
168168
}
169169
case FD_FLAMENCO_TYPE_CSTR:
170-
fprintf( file, "'%s',", (char const *)arg );
170+
if( arg==NULL ) {
171+
fprintf( file, "," );
172+
} else {
173+
fprintf( file, "'%s',", (char const *)arg );
174+
}
171175
break;
172176
case FD_FLAMENCO_TYPE_ENUM_DISC: {
173177
char lowercase_variant[128];
@@ -182,7 +186,7 @@ custom_serializer_walk( void * _self,
182186
default:
183187
FD_LOG_CRIT(( "unknown type %#x", (uint)type ));
184188
break;
185-
}
189+
}
186190
}
187191

188192
static int
@@ -200,7 +204,7 @@ fd_runtime_fuzz_decode_type_run( fd_runtime_fuzz_runner_t * runner,
200204

201205
// First byte is the type ID
202206
uchar type_id = input[0];
203-
if (type_id >= FD_TYPE_NAME_COUNT) {
207+
if( type_id >= FD_TYPE_NAME_COUNT ) {
204208
FD_LOG_WARNING(( "Invalid type ID: %d", type_id ));
205209
*output_sz = 0;
206210
return 0;
@@ -277,7 +281,6 @@ fd_runtime_fuzz_decode_type_run( fd_runtime_fuzz_runner_t * runner,
277281
*output_sz = 0;
278282
return 0;
279283
}
280-
281284
long serialized_sz = ftell( file );
282285
fclose( file );
283286

@@ -324,11 +327,11 @@ fd_runtime_fuzz_decode_type_run( fd_runtime_fuzz_runner_t * runner,
324327
}
325328

326329
ulong
327-
fd_runtime_fuzz_type_run( fd_runtime_fuzz_runner_t * runner,
328-
void const * input_,
329-
void ** output_,
330-
void * output_buf,
331-
ulong output_bufsz ) {
330+
fd_runtime_fuzz_type_run( fd_runtime_fuzz_runner_t * runner,
331+
void const * input_,
332+
void ** output_,
333+
void * output_buf,
334+
ulong output_bufsz ) {
332335
fd_exec_test_type_context_t const * input = fd_type_pun_const( input_ );
333336
fd_exec_test_type_effects_t ** output = fd_type_pun( output_ );
334337

@@ -356,24 +359,23 @@ fd_runtime_fuzz_type_run( fd_runtime_fuzz_runner_t * runner,
356359
effects->yaml = NULL;
357360

358361
// Decode the type
359-
ulong max_content_size = output_bufsz - (_l - (ulong)output_buf);
360-
uchar* temp_buffer = FD_SCRATCH_ALLOC_APPEND(l, alignof(uchar), max_content_size);
362+
ulong max_content_size = output_bufsz - (_l - (ulong)output_buf);
363+
uchar * temp_buffer = (uchar *)_l;
361364
if (FD_UNLIKELY(_l > output_end)) {
362365
return 0UL;
363366
}
364367

365368
ulong decoded_sz = max_content_size;
366-
int success = fd_runtime_fuzz_decode_type_run(
367-
runner,
368-
input->content->bytes,
369-
input->content->size,
370-
temp_buffer,
371-
&decoded_sz);
369+
int success = fd_runtime_fuzz_decode_type_run( runner,
370+
input->content->bytes,
371+
input->content->size,
372+
temp_buffer,
373+
&decoded_sz);
372374

373375
if (!success || decoded_sz == 0) {
374-
effects->result = 0;
375-
} else {
376376
effects->result = 1;
377+
} else {
378+
effects->result = 0;
377379

378380
// The decoded data contains:
379381
// - serialized_sz (ulong)
@@ -386,7 +388,7 @@ fd_runtime_fuzz_type_run( fd_runtime_fuzz_runner_t * runner,
386388
// Allocate and copy the representation (serialized data)
387389
effects->representation = FD_SCRATCH_ALLOC_APPEND(l, alignof(pb_bytes_array_t),
388390
PB_BYTES_ARRAY_T_ALLOCSIZE(serialized_sz));
389-
if (FD_UNLIKELY(_l > output_end)) {
391+
if( FD_UNLIKELY( _l > output_end ) ) {
390392
return 0UL;
391393
}
392394
effects->representation->size = (pb_size_t)serialized_sz;
@@ -396,7 +398,7 @@ fd_runtime_fuzz_type_run( fd_runtime_fuzz_runner_t * runner,
396398
ulong yaml_sz = decoded_sz - sizeof(ulong) - serialized_sz;
397399
effects->yaml = FD_SCRATCH_ALLOC_APPEND(l, alignof(pb_bytes_array_t),
398400
PB_BYTES_ARRAY_T_ALLOCSIZE(yaml_sz));
399-
if (FD_UNLIKELY(_l > output_end)) {
401+
if( FD_UNLIKELY( _l > output_end ) ) {
400402
return 0UL;
401403
}
402404
effects->yaml->size = (pb_size_t)yaml_sz;

src/flamenco/types/fd_types.c

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)