主要内容

被污染的数据缺陷

与来自不安全来源的代码元素相关的缺陷

被污染的数据缺陷用来标记在某些运算中使用了被污染的数据。来自不安全来源的数据是被污染的数据。Polyspace® 认为以下来源不安全:

  • 易失对象。

  • 使用标准库函数获取的外部输入。外部输入可能包括:

    • 用户输入

    • 环境变量

    • 文件内容或文件路径

    • 从硬件获取的数据

在使用数据之前,请验证从这类不安全来源获取的被污染数据。恶意攻击者可能会使用未经验证的被污染数据攻击您的程序并造成故障。被污染的数据缺陷用来标记在某些运算中使用了未经验证的被污染数据。例如,Polyspace 会标记:

  • 各个数值运算中的被污染数据。

  • 在外部控制的元素,例如路径、命令、环境变量和主机 ID。

  • 内存操作(例如分配和取消引用)中的被污染数据。

Polyspace 结果

使用被污染的索引进行数组访问来自不安全源的数组索引可能超出数组范围
从外部控制路径执行的命令Path argument from an unsecure source
执行外部控制命令Command argument from an unsecure source vulnerable to operating system command injection
使用外部控制元素进行主机更改Changing host ID from an unsecure source
从外部控制路径加载的库Using a library argument from an externally controlled path
循环界限值被污染Loop controlled by a value from an unsecure source
内存分配大小被污染Size argument to memory function is from an unsecure source
使用被污染的偏移量进行指针解引用Offset is from an unsecure source and dereference might be out of bounds
除法操作数被污染Operands of division operation (/) come from an unsecure source
模操作数被污染Operands of remainder operation (%) come from an unsecure source
被污染的 NULL 或不以 null 结尾的字符串Argument is from an unsecure source and might be NULL or not NULL-terminated
符号变化转换被污染Value from an unsecure source changes sign
可变长度数组大小被污染Size of the variable-length array (VLA) is from an unsecure source and might be zero, negative, or too large
敏感函数使用了污染源Data obtained from an untrusted source is passed to user-defined sensitive function (自 R2023b 起)
字符串格式被污染Input format argument is from an unsecure source
使用外部控制的环境变量Value of environment variable is from an unsecure source
使用被污染的指针Pointer from an unsecure source may be NULL or point to unknown memory

主题