Skip to content

Commit 76f1aac

Browse files
Fix #12951 nullptr dereference in CheckLeakAutoVar::checkScope() (#6613)
1 parent 5aebb2c commit 76f1aac

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

cfg/sqlite3.cfg

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,49 @@
10271027
<not-bool/>
10281028
</arg>
10291029
</function>
1030+
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_open -->
1031+
<!-- int sqlite3_open16(const void *filename, /* Database filename (UTF-16) */
1032+
sqlite3 **ppDb /* OUT: SQLite db handle */); -->
1033+
<function name="sqlite3_open16">
1034+
<noreturn>false</noreturn>
1035+
<returnValue type="int"/>
1036+
<arg nr="1" direction="in">
1037+
<not-null/>
1038+
<not-uninit/>
1039+
<strz/>
1040+
</arg>
1041+
<arg nr="2" direction="out">
1042+
<not-null/>
1043+
<not-bool/>
1044+
</arg>
1045+
</function>
1046+
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_open -->
1047+
<!-- int sqlite3_open_v2(const char *filename, /* Database filename (UTF-8) */
1048+
sqlite3 **ppDb, /* OUT: SQLite db handle */
1049+
int flags, /* Flags */
1050+
const char *zVfs /* Name of VFS module to use */); -->
1051+
<function name="sqlite3_open_v2">
1052+
<noreturn>false</noreturn>
1053+
<returnValue type="int"/>
1054+
<arg nr="1" direction="in">
1055+
<not-null/>
1056+
<not-uninit/>
1057+
<strz/>
1058+
</arg>
1059+
<arg nr="2" direction="out">
1060+
<not-null/>
1061+
<not-bool/>
1062+
</arg>
1063+
<arg nr="3" direction="in">
1064+
<not-uninit/>
1065+
<not-bool/>
1066+
</arg>
1067+
<arg nr="4" direction="in">
1068+
<not-null/>
1069+
<not-uninit/>
1070+
<strz/>
1071+
</arg>
1072+
</function>
10301073
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_prepare -->
10311074
<!-- int sqlite3_prepare(sqlite3 *db, /* Database handle */
10321075
const char *zSql, /* SQL statement, UTF-8 encoded */

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
555555
if (info.second.status != VarInfo::ALLOC)
556556
return false;
557557
const Token* ret = getReturnValueFromOutparamAlloc(info.second.allocTok, *mSettings);
558-
return ret && ret->varId() && ret->varId() == vartok->varId();
558+
return ret && vartok && ret->varId() && ret->varId() == vartok->varId();
559559
})) {
560560
varInfo1.clear();
561561
}

test/cfg/sqlite3.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ void resourceLeak_sqlite3_open()
4646
// cppcheck-suppress resourceLeak
4747
}
4848

49+
void resourceLeak_sqlite3_open_v2(const char* Filename, int Flags, int Timeout, const char* Vfs) { // #12951, don't crash
50+
sqlite3* handle;
51+
const int ret = sqlite3_open_v2(Filename, &handle, Flags, Vfs);
52+
if (SQLITE_OK != ret) {}
53+
if (Timeout > 0) {}
54+
// cppcheck-suppress resourceLeak
55+
}
56+
4957
void ignoredReturnValue(const char * buf)
5058
{
5159
// cppcheck-suppress leakReturnValNotUsed

0 commit comments

Comments
 (0)