Skip to content

Commit 9de3067

Browse files
author
Laszlo Ersek
committed
BaseTools/GenVtf: silence false "stringop-overflow" warning with memcpy()
gcc-8 (which is part of Fedora 28) enables the new warning "-Wstringop-overflow" in "-Wall". This warning is documented in detail at <https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the introduction says > Warn for calls to string manipulation functions such as memcpy and > strcpy that are determined to overflow the destination buffer. It breaks the BaseTools build with: > GenVtf.c: In function 'ConvertVersionInfo': > GenVtf.c:132:7: error: 'strncpy' specified bound depends on the length > of the source argument [-Werror=stringop-overflow=] > strncpy (TemStr + 4 - Length, Str, Length); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > GenVtf.c:130:14: note: length computed here > Length = strlen(Str); > ^~~~~~~~~~~ It is a false positive because, while the bound equals the length of the source argument, the destination pointer is moved back towards the beginning of the destination buffer by the same amount (and this amount is range-checked first, so we can't precede the start of the dest buffer). Replace both strncpy() calls with memcpy(). Cc: Ard Biesheuvel <[email protected]> Cc: Cole Robinson <[email protected]> Cc: Liming Gao <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Yonghong Zhu <[email protected]> Reported-by: Cole Robinson <[email protected]> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <[email protected]> Reviewed-by: Liming Gao <[email protected]>
1 parent 9222154 commit 9de3067

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

BaseTools/Source/C/GenVtf/GenVtf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ Routine Description:
129129
} else {
130130
Length = strlen(Str);
131131
if (Length < 4) {
132-
strncpy (TemStr + 4 - Length, Str, Length);
132+
memcpy (TemStr + 4 - Length, Str, Length);
133133
} else {
134-
strncpy (TemStr, Str + Length - 4, 4);
134+
memcpy (TemStr, Str + Length - 4, 4);
135135
}
136136

137137
sscanf (

0 commit comments

Comments
 (0)