Skip to content

Commit 583f64a

Browse files
two-heartripatel-fd
authored andcommitted
codeql chores
update queries, delte obsolte queries, fix findings, add back simpler version of alloca in loop
1 parent a37a2f6 commit 583f64a

File tree

9 files changed

+53
-96
lines changed

9 files changed

+53
-96
lines changed

contrib/codeql/dev/VisualizeTopology.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cpp
22

3-
/* Point this predicate to the topology to be visualized. Make sure it is part of the DB */
3+
/* Point this predicate to the topology to be visualized */
44
predicate inTopology(Location loc) {
55
loc.getFile().getRelativePath() = "src/app/firedancer/topology.c" or
66
loc.getFile().getRelativePath() = "src/disco/net/fd_net_tile_topo.c"
@@ -70,7 +70,7 @@ class OutLink extends FunctionCall {
7070
or
7171
(
7272
this.getTarget().hasName("fd_topos_net_rx_link") and
73-
name = this.getArgument(2).(StringLiteral).getValue() and
73+
name = this.getArgument(1).(StringLiteral).getValue() and
7474
out_tile = "net" and /* leaving aside the sock alternative */
7575
inTopology(this.getLocation())
7676
)

contrib/codeql/nightly/AccountDerefBeforeModify.ql

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @name Alloca call in loop
3+
* @description We want to strictly forbid alloca in loops to avoid
4+
* stack overflows
5+
* @kind problem
6+
* @problem.severity warning
7+
* @precision high
8+
* @id asymmetric-research/alloca-in-loop
9+
*/
10+
11+
import cpp
12+
13+
class AllocaCall extends FunctionCall {
14+
AllocaCall() {
15+
this.getTarget().hasName("fd_alloca") or
16+
this.getTarget().hasName("alloca") or
17+
this.getTarget().hasName("fd_alloca_check") or
18+
this.getTarget().hasName("__builtin_alloca")
19+
}
20+
}
21+
22+
from Loop l, AllocaCall c
23+
where c.getAPredecessor*() = l
24+
select c, "Call to alloca in loop"

contrib/codeql/nightly/TrivialMemcpy.ql

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,27 @@ class MemcpyFunction extends Function {
2323
}
2424
}
2525

26-
from FunctionCall call, MemcpyFunction memcpy
26+
predicate ignoredLocation(Location l) {
27+
// we don't want to change vendored code if not really necessary
28+
l.getFile().getBaseName() = "cJSON.c"
29+
}
30+
31+
class InScopeType extends Type {
32+
InScopeType() {
33+
not this instanceof CharType and
34+
not this instanceof VoidType and
35+
not this.getUnspecifiedType().(DerivedType).getBaseType().getUnspecifiedType().hasName(["fd_txn_p", "fd_hash"])
36+
}
37+
}
38+
39+
from FunctionCall call, MemcpyFunction memcpy, InScopeType t
2740
where
2841
included(call.getLocation()) and
2942
not call.isInMacroExpansion() and
43+
not ignoredLocation(call.getLocation()) and
3044
call.getTarget() = memcpy and
3145
call.getArgument(2) instanceof SizeofTypeOperator and
32-
call.getArgument(0).getUnspecifiedType() = call.getArgument(1).getUnspecifiedType() and
33-
call.getArgument(0).getUnspecifiedType().(DerivedType).getBaseType().getUnspecifiedType() = call.getArgument(2).(SizeofTypeOperator).getTypeOperand().getUnspecifiedType()
34-
select call, "Call to " + memcpy.getName() + " could be rewritten as an assignment."
46+
t = call.getArgument(0).getUnspecifiedType() and
47+
t = call.getArgument(1).getUnspecifiedType() and
48+
t.(DerivedType).getBaseType().getUnspecifiedType() = call.getArgument(2).(SizeofTypeOperator).getTypeOperand().getUnspecifiedType()
49+
select call, "Call to " + memcpy.getName() + " could be rewritten as an assignment." + t.getUnderlyingType()

src/app/firedancer/callbacks.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ funk_loose( fd_topo_t const * topo,
114114
static void
115115
funk_new( fd_topo_t const * topo,
116116
fd_topo_obj_t const * obj ) {
117-
(void)topo;
118117
ulong funk_seed = fd_pod_queryf_ulong( topo->props, 0UL, "obj.%lu.seed", obj->id );
119118
if( !funk_seed ) FD_TEST( fd_rng_secure( &funk_seed, sizeof(ulong) ) );
120119
FD_TEST( fd_funk_new( fd_topo_obj_laddr( topo, obj->id ), 2UL, funk_seed, VAL("txn_max"), VAL("rec_max") ) );

src/disco/bundle/fd_bundle_tile.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,6 @@ crypto_realloc( void * addr,
286286
ulong num,
287287
char const * file,
288288
int line ) {
289-
(void)file;
290-
(void)line;
291-
292289
if( FD_UNLIKELY( !addr ) ) return crypto_malloc( num, file, line );
293290
if( FD_UNLIKELY( !num ) ) {
294291
crypto_free( addr, file, line );

src/discof/shredcap/fd_shredcap_tile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ static inline void
160160
during_frag( fd_capture_tile_ctx_t * ctx,
161161
ulong in_idx,
162162
ulong seq FD_PARAM_UNUSED,
163-
ulong sig FD_PARAM_UNUSED,
163+
ulong sig,
164164
ulong chunk,
165165
ulong sz,
166-
ulong ctl FD_PARAM_UNUSED ) {
166+
ulong ctl ) {
167167
ctx->skip_frag = 0;
168168
if( ctx->in_kind[ in_idx ]==SHRED_REPAIR ) {
169169
if( !is_fec_completes_msg( sz ) ) {
@@ -343,7 +343,7 @@ after_frag( fd_capture_tile_ctx_t * ctx,
343343

344344
static ulong
345345
populate_allowed_fds( fd_topo_t const * topo FD_PARAM_UNUSED,
346-
fd_topo_tile_t const * tile FD_PARAM_UNUSED,
346+
fd_topo_tile_t const * tile,
347347
ulong out_fds_cnt FD_PARAM_UNUSED,
348348
int * out_fds ) {
349349
ulong out_cnt = 0UL;

src/discof/tower/fd_tower_tile.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ during_frag( ctx_t * ctx,
263263
static void
264264
after_frag( ctx_t * ctx,
265265
ulong in_idx,
266-
ulong seq FD_PARAM_UNUSED,
266+
ulong seq FD_PARAM_UNUSED,
267267
ulong sig,
268268
ulong sz,
269-
ulong tsorig FD_PARAM_UNUSED,
270-
ulong tspub FD_PARAM_UNUSED,
271-
fd_stem_context_t * stem FD_PARAM_UNUSED ) {
269+
ulong tsorig,
270+
ulong tspub FD_PARAM_UNUSED,
271+
fd_stem_context_t * stem ) {
272272
uint in_kind = ctx->in_kind[in_idx];
273273
if( FD_UNLIKELY( in_kind != IN_KIND_REPLAY ) ) return;
274274

src/flamenco/runtime/context/fd_exec_slot_ctx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx,
230230
/* Fee Rate Governor */
231231

232232
fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( slot_ctx->bank );
233-
fd_memcpy( fee_rate_governor, &old_bank->fee_rate_governor, sizeof(fd_fee_rate_governor_t) );
233+
*fee_rate_governor = old_bank->fee_rate_governor;
234234

235235
/* Capitalization */
236236

0 commit comments

Comments
 (0)