mariadb/dbug
Mikhail Chalov 567b681299 Minimize unsafe C functions usage - replace strcat() and strcpy() (and strncat() and strncpy()) with custom safe_strcat() and safe_strcpy() functions
The MariaDB code base uses strcat() and strcpy() in several
places. These are known to have memory safety issues and their usage is
discouraged. Common security scanners like Flawfinder flags them. In MariaDB we
should start using modern and safer variants on these functions.

This is similar to memory issues fixes in 19af1890b5
and 9de9f105b5 but now replace use of strcat()
and strcpy() with safer options strncat() and strncpy().

However, add '\0' forcefully to make sure the result string is correct since
for these two functions it is not guaranteed what new string will be null-terminated.

Example:

    size_t dest_len = sizeof(g->Message);
    strncpy(g->Message, "Null json tree", dest_len); strncat(g->Message, ":",
    sizeof(g->Message) - strlen(g->Message)); size_t wrote_sz = strlen(g->Message);
    size_t cur_len = wrote_sz >= dest_len ? dest_len - 1 : wrote_sz;
    g->Message[cur_len] = '\0';

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the BSD-new
license. I am contributing on behalf of my employer Amazon Web Services

-- Reviewer and co-author Vicențiu Ciorbaru <vicentiu@mariadb.org>
-- Reviewer additions:
* The initial function implementation was flawed. Replaced with a simpler
  and also correct version.
* Simplified code by making use of snprintf instead of chaining strcat.
* Simplified code by removing dynamic string construction in the first
  place and using static strings if possible. See connect storage engine
  changes.
2023-01-20 15:18:52 +02:00
..
CMakeLists.txt cmake: fewer Build-Depends in SRPM 2021-05-22 21:56:51 +02:00
dbug.c Minimize unsafe C functions usage - replace strcat() and strcpy() (and strncat() and strncpy()) with custom safe_strcat() and safe_strcpy() functions 2023-01-20 15:18:52 +02:00
dbug_add_tags.pl mtr: use env for perl 2020-06-23 03:24:46 +02:00
dbug_long.h
example1.c
example2.c
example3.c
factorial.c remove duplicate code from the factorial dbug example 2012-08-23 15:30:43 +02:00
main.c
monty.doc
my_main.c Fix clang-15 -Wdeprecated-non-prototype 2022-07-01 09:34:31 +03:00
remove_function_from_trace.pl mtr: use env for perl 2020-06-23 03:24:46 +02:00
tests-t.pl move safemalloc out of dbug. 2011-12-12 22:58:24 +01:00
tests.c add WITH_DBUG_TRACE CMake variable 2020-04-29 20:13:14 +03:00
user.r Fix typos in the codebase. 2022-08-09 18:41:09 +03:00