ton CVE semgrep_id:flawfinder.strcpy-1:289:289
Insecure string processing function (strcpy)
Ссылка на строку:
https://dev.gitsec.ru/crypto/ton/-/blob/master/tdutils/td/utils/port/stacktrace.cpp#L289
Уязвимость
Название: небезопасная функция обработки строк (strcpy).
Описание: функция strcpy не предоставляет возможности проверять размер буфера перед копированием данных в целевой буфер. Это может привести к переполнению буфера, что, в свою очередь, может вызвать сбои в работе программы или позволить злоумышленнику выполнить произвольный код.
Варианты исправления
- Использование
strncpyс указанием максимального размера буфера:
strncpy(buf_ptr, "] ", MAX_SIZE);
buf_ptr[MAX_SIZE - 1] = '\0'; // Убедиться, что строка завершается нулём
buf_ptr += strlen(buf_ptr);
Здесь MAX_SIZE — это максимальный размер буфера, который должен быть определён в коде.
- Использование более безопасных версий функций в CRT (для Microsoft C Runtime Library):
strncpy_s(buf_ptr, MAX_SIZE, "] ", MAX_SIZE);
buf_ptr += strlen(buf_ptr);
Ссылки на статьи
-
Документация по
strncpy. - Более безопасные версии функций в CRT.
- CWE-120: Buffer Copy without Checking Size of Input (‘Classic Buffer Overflow’).
Описание:
The `strcpy` family of functions do not provide the ability to limit or check buffer sizes before copying to a destination buffer. This can lead to buffer overflows. Consider using more secure alternatives such as `strncpy` and provide the correct limit to the destination buffer and ensure the string is null terminated.For more information please see: https://linux.die.net/man/3/strncpy
If developing for C Runtime Library (CRT), more secure versions of these functions should be used, see: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l?view=msvc-170
Исходный JSON:
{
"id": "cb77f13357a5efb6d17c9d7aaf5352d85c0e03196a75bc01877b6d9c21ec2f71",
"category": "sast",
"name": "Insecure string processing function (strcpy)",
"description": "The `strcpy` family of functions do not provide the ability to limit or check buffer\nsizes before copying to a destination buffer. This can lead to buffer overflows. Consider\nusing more secure alternatives such as `strncpy` and provide the correct limit to the\ndestination buffer and ensure the string is null terminated.\n\nFor more information please see: https://linux.die.net/man/3/strncpy\n\nIf developing for C Runtime Library (CRT), more secure versions of these functions should be\nused, see:\nhttps://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l?view=msvc-170\n",
"cve": "semgrep_id:flawfinder.strcpy-1:289:289",
"severity": "High",
"scanner": {
"id": "semgrep",
"name": "Semgrep"
},
"location": {
"file": "repo/tdutils/td/utils/port/stacktrace.cpp",
"start_line": 289
},
"identifiers": [
{
"type": "semgrep_id",
"name": "flawfinder.strcpy-1",
"value": "flawfinder.strcpy-1"
},
{
"type": "cwe",
"name": "CWE-120",
"value": "120",
"url": "https://cwe.mitre.org/data/definitions/120.html"
},
{
"type": "owasp",
"name": "A03:2021 - Injection",
"value": "A03:2021"
},
{
"type": "owasp",
"name": "A1:2017 - Injection",
"value": "A1:2017"
},
{
"type": "flawfinder_func_name",
"name": "Flawfinder - strcpy",
"value": "strcpy"
}
]
}
```