Skip to content

Commit 39574c6

Browse files
Fix #15124 FN bufferAccessOutOfBounds with wmemcpy() (#8951)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent a202452 commit 39574c6

4 files changed

Lines changed: 53 additions & 11 deletions

File tree

‎cfg/gnu.cfg‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@
650650
<not-bool/>
651651
</arg>
652652
</function>
653-
<!-- https://man7.org/linux/man-pages/man3/mempcpy.3.html-->
653+
<!-- https://man7.org/linux/man-pages/man3/wmempcpy.3.html -->
654654
<!-- wchar_t *wmempcpy(wchar_t *restrict dest, const wchar_t *restrict src, size_t n);-->
655655
<function name="wmempcpy">
656656
<returnValue type="wchar_t *"/>
@@ -659,12 +659,12 @@
659659
<not-overlapping-data ptr1-arg="1" ptr2-arg="2" size-arg="3"/>
660660
<arg nr="1" direction="out">
661661
<not-null/>
662-
<minsize type="argvalue" arg="3"/>
662+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
663663
</arg>
664664
<arg nr="2" direction="in">
665665
<not-null/>
666666
<not-uninit/>
667-
<minsize type="argvalue" arg="3"/>
667+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
668668
</arg>
669669
<arg nr="3" direction="in">
670670
<not-uninit/>

‎cfg/std.cfg‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3928,7 +3928,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
39283928
<arg nr="1">
39293929
<not-null/>
39303930
<not-uninit/>
3931-
<minsize type="argvalue" arg="3"/>
3931+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
39323932
</arg>
39333933
<arg nr="2" direction="in">
39343934
<not-uninit/>
@@ -3974,12 +3974,12 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
39743974
<arg nr="1" direction="in">
39753975
<not-null/>
39763976
<not-uninit/>
3977-
<minsize type="argvalue" arg="3"/>
3977+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
39783978
</arg>
39793979
<arg nr="2" direction="in">
39803980
<not-null/>
39813981
<not-uninit/>
3982-
<minsize type="argvalue" arg="3"/>
3982+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
39833983
</arg>
39843984
<arg nr="3" direction="in">
39853985
<not-uninit/>
@@ -4016,12 +4016,12 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
40164016
<not-overlapping-data ptr1-arg="1" ptr2-arg="2" count-arg="3"/>
40174017
<arg nr="1" direction="out">
40184018
<not-null/>
4019-
<minsize type="argvalue" arg="3"/>
4019+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
40204020
</arg>
40214021
<arg nr="2" direction="in">
40224022
<not-null/>
40234023
<not-uninit/>
4024-
<minsize type="argvalue" arg="3"/>
4024+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
40254025
</arg>
40264026
<arg nr="3" direction="in">
40274027
<not-uninit/>
@@ -4081,13 +4081,13 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
40814081
<leak-ignore/>
40824082
<arg nr="1" direction="out">
40834083
<not-null/>
4084-
<minsize type="argvalue" arg="3"/>
4084+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
40854085
</arg>
40864086
<arg nr="2">
40874087
<!-- TODO: direction? memory could be overwritten -->
40884088
<not-null/>
40894089
<not-uninit/>
4090-
<minsize type="argvalue" arg="3"/>
4090+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
40914091
</arg>
40924092
<arg nr="3" direction="in">
40934093
<not-uninit/>
@@ -4141,7 +4141,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
41414141
<leak-ignore/>
41424142
<arg nr="1" direction="out">
41434143
<not-null/>
4144-
<minsize type="argvalue" arg="3"/>
4144+
<minsize type="argvalue" arg="3" baseType="wchar_t"/>
41454145
</arg>
41464146
<arg nr="2" direction="in">
41474147
<not-uninit/>

‎test/cfg/gnu.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,13 @@ wchar_t *nullPointer_wmempcpy(wchar_t *dest, const wchar_t *src, size_t n)
376376
return wmempcpy(dest,src,n);
377377
}
378378

379+
void bufferAccessOutOfBounds_wmempcpy(const wchar_t *src)
380+
{
381+
wchar_t buf[3];
382+
// cppcheck-suppress bufferAccessOutOfBounds
383+
wmempcpy(buf, src, 5);
384+
}
385+
379386
int uninitvar_getpw(uid_t uid, char *buf)
380387
{
381388
uid_t someUid;

‎test/cfg/std.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,20 @@ void bufferAccessOutOfBounds_wcsncpy()
619619
wcsncpy(s, L"abc", 17);
620620
}
621621

622+
void bufferAccessOutOfBounds_wmemcpy()
623+
{
624+
wchar_t a[4];
625+
// cppcheck-suppress bufferAccessOutOfBounds
626+
wmemcpy(a, L"abcd", 5);
627+
}
628+
629+
int bufferAccessOutOfBounds_wmemcmp(const wchar_t* b)
630+
{
631+
const wchar_t a[4] = { L'a', L'b', L'c', L'd' };
632+
// cppcheck-suppress bufferAccessOutOfBounds
633+
return wmemcmp(a, b, 5);
634+
}
635+
622636
int nullPointer_wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n)
623637
{
624638
// cppcheck-suppress nullPointer
@@ -2940,6 +2954,27 @@ void *bufferAccessOutOfBounds_memchr(const void *s, int c, size_t n)
29402954
return memchr(s,c,n);
29412955
}
29422956

2957+
bool bufferAccessOutOfBounds_wmemchr(wchar_t c)
2958+
{
2959+
const wchar_t buf[] = {'a', 'b', 'c'};
2960+
// cppcheck-suppress bufferAccessOutOfBounds
2961+
return wmemchr(buf, c, 5) != NULL;
2962+
}
2963+
2964+
void bufferAccessOutOfBounds_wmemset(wchar_t c)
2965+
{
2966+
wchar_t buf[3];
2967+
// cppcheck-suppress bufferAccessOutOfBounds
2968+
wmemset(buf, c, 5);
2969+
}
2970+
2971+
void bufferAccessOutOfBounds_wmemmove(const wchar_t* s)
2972+
{
2973+
wchar_t d[3];
2974+
// cppcheck-suppress bufferAccessOutOfBounds
2975+
wmemmove(d, s, 5);
2976+
}
2977+
29432978
void uninitvar_wmemchr(void)
29442979
{
29452980
const wchar_t *cs;

0 commit comments

Comments
 (0)