NucleiStudio Code Analysis

本文详细介绍了Nuclei Studio的代码分析设置,包括代码风格、潜在编程问题、安全漏洞和语法及语义错误四个方面。内容涵盖避免魔法数字、禁止使用goto语句、检查赋值操作、类成员初始化等众多编程最佳实践,旨在提升代码质量和安全性。此外,还提及了如未使用的函数声明、格式化字符串漏洞等常见问题及其规避方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        本节主要描述下NucleiStudio project -> Properties -> C/C++ General -> Code Analysis下的setting。NucleiStudio的代码分析分为以下四个部分:代码风格、潜在编程问题、安全漏洞和语法和语义错误,我们可以根据实际情况选择规则的preferences, scope and launch options。

Code Style

1、avoid magic numbers:避免使用魔鬼数字;

2、c-style cast instead of c++ cast:在C++文件里使用c风格类型转换代替c++风格类型转换;

3、function or method is blacklisted:禁止使用黑名单中的函数或方法;

4、Goto statement used:禁止使用goto语句;

5、lack of copyright information:缺少版权信息,正则表达式会检索.*CopyRight.*;

6、line comments:禁止使用'//'行注释,该规则仅检查C代码,不检查c++;

7、Missing reference return value in assignment operator:赋值运算符中缺少引用返回值;

8、Multiple variable declaration:禁止在同一行定义多个变量;

9、Name convention for function:函数命名约束;

10、Nesting comments:注释嵌套,Sequence ''/*'' used inside the comment;

11、return with parenthesis:返回值用括号括起来;

12、using directive in header:c++ coding standard,在头文件中使用‘using’指令;

Potential Programming problems

1、Assignment in condition:检查条件语句中的赋值,eg if(a=b);

2、Assignment to itself:检查表达式中左值和右值是否是一样的,eg. var = var;

3、Catching by reference is recommended:c++ coding standard;

4、Class has a virtual method and non-virtual destructor:有虚函数就要有虚析构函数;

5、class members should be properly initialized:c++ coding standard,类成员应该被正确初始化;

6、Direct float comparison:通过查看两个数字是否“接近”来比较两个浮点数。如果您基于错误分析、测试或任意猜测,决定结果应始终在预期结果的0.00001以内,则可以将比较更改为:if (fabs(result - expectedResult) < 0.00001),最大错误值通常称为epsilon;

7、Invalid 'decltype(auto)' specifier:c++ coding standard,无效的‘decltype(auto)' 说明符,combining ‘decltype(auto)' with other type specifier is not allowed;

8、miss copy construct or assignment operator:this flag will flag classes with pointer members without copy constructor or assignment operator;Shallow copy can have negative run-time effects,explicit copy constructors/assignment operators for classes with reference/pointer should  be used;此标志将标记具有指针成员的类,这些指针成员不含拷贝构造函数或赋值运算符。Shallow copy浅拷贝可能会对运行时产生负面影响,应使用具有引用/指针的类的显式拷贝构造函数/赋值运算符。

9、missing cases in switch;

10、missing default in switch;

11、missing self check in assignment operator;

12、no break at end of case;

13、no return;

14、no return value;

15、returning the address of a local variable:返回局部变量的地址;

16、return value not evaluated:返回值没有被检查评估;

17、statement has no effect:语句无效,检查诸如'a;' or '-a;' or 'a-b;' 这种看起来没有作用的语句;

18、static variable in header file:检查头文件中的静态变量,定义在头文件中的静态变量会被引用该头文件的c文件重复定义;

19、suggested parenthesis around expression:建议表达式用括号括起来。this checker finds problems related to either lack of understanding precedence of operators or misspelling of operators in expression.for example (!a < 10) or (a & b);

20、suspicious semicolon:可疑的分号。a semicolon is used as a null statement in a condition.for example,'if(expression);';

21、symbol shadowing:符号阴影。this rule will flag symbols,like local variables,class fields or method parameters,shadowing another symbol in upper scope.symbol 'x' is masking symbol declared in upper scope;此规则将标记符号,如局部变量、类字段或方法参数,以遮蔽在上层作用域的另一个符号。“x”是在上层作用域中声明的masking symbol;

22、unused function declaration:未使用的函数声明;

23、unused return value:函数返回了一个值,但是函数声明为void;

24、unused static function:find static functions which cannot be possible used not being referenced inside the file;

25、unused variable declaration in file scope:文件范围内未使用的变量声明;

26、virtual method call in constructor/destructor:c++ coding standard,构造函数/析构函数中的虚拟方法调用;

security vulnerabilities

format string vulnerability:格式化字符串漏洞,eg char[5] str;scanf("%10s",str);

Syntax and Semantic Errors

1、abstract class cannot be instantiated:抽象的类不能被实例化;

2、ambigous problem:模糊问题,可能原因:用户定义的变量名与函数库中的名字相同;把{ }大括号打成了[ ]等等;

3、circular inheritance:c++ coding standard,循环继承;

4、field cannot be resolved:字段无法被解析;

5、invalid arguments;

6、invalid overload:c++ coding standard,无效重载;

7、invalid redeclaration;

8、invalid redefinition;

9、invalid template argument:c++ coding standard,无效的template参数;

10、label statement not found;

11、method cannot be resolved:方法不能被解析;

12、symbol is not resolved:符号不能被解析;

13、type cannot be resolved:类型不能被解析;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值