Insecure Buffer Access High

We recommend you to avoid using insecure functions in your code. This functions, when used improperly, does not consider buffer boundaries and can lead to buffer overflows.

Detector ID
c/insecure-buffer-access@v1.0
Category
Common Weakness Enumeration (CWE) external icon
Tags
-

Noncompliant example

1#include <stdio.h>
2#include <string.h>
3
4int DST_BUFFER_SIZE = 120;
5
6int insecureBufferAccessNonCompliant() {
7    char str[DST_BUFFER_SIZE];
8    // Noncompliant: use of scanf function 
9    scanf("%s", str);
10    printf("%s", str);
11    return 0;
12}

Compliant example

1#include <stdio.h>
2#include <string.h>
3
4void insecureBufferAccessCompliant(char* src, char* dest, int dest_size) {
5  if (strlen(src) < dest_size) {
6    // Compliant: Bounds checking
7    strcat(dest, src);
8  }
9}