Bug 1475882 - clang-analyzer: Enable clang-analyzer-unix.cstring.BadSizeArg check. r=andi

Check the size argument passed to strncat for common erroneous patterns. There are currently no clang-analyzer-unix.cstring.BadSizeArg warnings in mozilla-central!

https://clang-analyzer.llvm.org/available_checks.html

MozReview-Commit-ID: DUI3ZNIBoLQ
This commit is contained in:
Chris Peterson
2018-07-14 23:15:37 -07:00
parent ba55fbae83
commit f0885d6a00
4 changed files with 14 additions and 0 deletions

View File

@@ -34,6 +34,8 @@ clang_checkers:
publish: !!bool yes
- name: clang-analyzer-security.insecureAPI.vfork
publish: !!bool yes
- name: clang-analyzer-unix.cstring.BadSizeArg
publish: !!bool yes
- name: misc-argument-comment
publish: !!bool yes
- name: misc-assert-side-effect

View File

@@ -0,0 +1,9 @@
// https://clang-analyzer.llvm.org/available_checks.html
#include "structures.h"
void test()
{
char dest[3];
strncat(dest, "***", sizeof(dest)); // warning : potential buffer overflow
}

View File

@@ -0,0 +1 @@
"[[\"warning\", \"Potential buffer overflow. Replace with 'sizeof(dest) - strlen(dest) - 1' or use a safer 'strlcat' API\", \"clang-analyzer-unix.cstring.BadSizeArg\"]]"

View File

@@ -87,3 +87,5 @@ int abort() { return 0; }
#define assert(x) \
if (!(x)) \
(void)abort()
char *strncat(char *s1, const char *s2, std::size_t n);