The documentation includes general guidance on adding coding rules, including which languages support adding custom rules, and general guidance on how to go about it.
If the docs don’t answer your question, please tell us:
- What language are you writing rules for? C/C++
- What have you tried, and what’s your challenge / stumbling block
Please share the relevant code snippet, along with any error messages you’re encountering:
The goal we want to achieve is to make sure that Microsoft banned functions are not used or at least alerted when being in use.
Reference from Microsoft and other sources:
Looking at the specific functions individually I can extract different rules in SonarQube that can be able to detect its usage.
However, I am thinking on a more friendly way of looking at that.
Would it be better to create custom rules? Is there a way to track all of them at the same time and make sure the ruleset detects that?
Here is what I found looking at the most critical functions.
SonarQube has built in rules for detecting usage of banned functions as you can see below:
#strcpy
Using “strcpy” or “wcscpy” is security-sensitive
#strcat
Using “strcat” or “wcscat” is security-sensitive
#strncpy
Using “strncpy” or “wcsncpy” is security-sensitive
#strncat
Using “strncat” or “wcsncat” is security-sensitive
#strtok
Non reentrant function ‘strtok’ called. For threadsafe applications it is recommended to use the reentrant replacement function ‘strtok_r’
#sprintf
“sprintf” should not be used
#vsprintf
vsprintf
#gmtime
Non reentrant function ‘gmtime’ called. For threadsafe applications it is recommended to use the reentrant replacement function ‘gmtime_r’
#localtime
Non reentrant function ‘localtime’ called. For threadsafe applications it is recommended to use the reentrant replacement function ‘localtime_r’
#ctime
“” should not be used
#ctime_r
Obsolete function ‘ctime_r’ called. It is recommended to use the function ‘strftime’ instead
#asctime
Obsolete POSIX functions should not be used
#asctime_r
Obsolete function ‘asctime_r’ called. It is recommended to use the function ‘strftime’ instead