From 06d8892e03008533712bcabfbd94daae4d335567 Mon Sep 17 00:00:00 2001
From: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
Date: Thu, 2 May 2024 14:22:27 +0100
Subject: [PATCH 1/4] C++: Rename an example file.
---
.../{StrncpyFlippedArgs.cpp => StrncpyFlippedArgsBad.cpp} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename cpp/ql/src/Likely Bugs/Memory Management/{StrncpyFlippedArgs.cpp => StrncpyFlippedArgsBad.cpp} (100%)
diff --git a/cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgs.cpp b/cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgsBad.cpp
similarity index 100%
rename from cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgs.cpp
rename to cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgsBad.cpp
From 8a261b7e7a2ac760daa54dd126f13fcf78290a0a Mon Sep 17 00:00:00 2001
From: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
Date: Thu, 2 May 2024 14:31:26 +0100
Subject: [PATCH 2/4] C++: Update StrncpyFlippedArgs.qhelp.
---
.../Memory Management/StrncpyFlippedArgs.qhelp | 9 +++++++--
.../Memory Management/StrncpyFlippedArgsBad.cpp | 11 +++++++++--
.../Memory Management/StrncpyFlippedArgsGood.cpp | 10 ++++++++++
3 files changed, 26 insertions(+), 4 deletions(-)
create mode 100644 cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgsGood.cpp
diff --git a/cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgs.qhelp b/cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgs.qhelp
index 2e297116710..9ba2b7c7c8e 100644
--- a/cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgs.qhelp
+++ b/cpp/ql/src/Likely Bugs/Memory Management/StrncpyFlippedArgs.qhelp
@@ -3,7 +3,7 @@
"qhelp.dtd">
The standard library function The standard library function strncpy copies a source string to a destination buffer. The third argument defines the maximum number of characters to copy and should be less than
+strncpy copies a source string to a destination buffer. The third argument defines the maximum number of characters to copy and should be less than
or equal to the size of the destination buffer. Calls of the form strncpy(dest, src, strlen(src)) or strncpy(dest, src, sizeof(src)) incorrectly set the third argument to the size of the source buffer. Executing a call of this type may cause a buffer overflow. Buffer overflows can lead to anything from a segmentation fault to a security vulnerability.strncpy(
not the source buffer.
In the following examples, the size of the source buffer is incorrectly used as a parameter to strncpy:
The corrected version uses the size of the destination buffer, or a variable containing the size of the destination buffer as the size parameter to strncpy:
In the following examples, the size of the source buffer is incorrectly used as a parameter to strncpy:
The corrected version uses the size of the destination buffer, or a variable containing the size of the destination buffer as the size parameter to strncpy: