Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Challenge: write a query to find this C NULL dereference #16516

catenacyber started this conversation in Ideas
Discussion options

See OISF/suricata#11098

The code is basically :

static void AllocAndProcessStep2(SomeStruct *r, otherargs...) {
 // do not check r, and dereference it !!!
 if (r->somefield) {
 // do something
 }
}
static SomeStruct * AllocAndProcessStep1(someargs) {
 if (unlikelyButMayHappen(someargs)) {
 return NULL;
 } 
 SomeStruct * r = malloc(somesize);
 if (r == NULL) {
 return NULL;
 }
 // fill some r fields
 return r;
}
static SomeStruct * AllocAndProcess(someargs) {
 SomeStruct * r = AllocAndProcessStep1(someargs);
 // do not check r
 AllocAndProcessStep2(r, ...);
 return r;
}
static void Parent() {
 SomeStruct * r = AllocAndProcess(someargs);
 if (r == NULL) {
 // log error, etc...
 return;
 }
}
You must be logged in to vote

Replies: 1 comment

Comment options

Trying something with #16524

Some interesting results, but most come from ignoring that allocations can fail...

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /