-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added coccinelle rule to find strlcpy on NameData
NameData is a fixed-size type of 64 bytes. Using strlcpy to copy data into a NameData struct can cause problems because any data that follows the initial null-terminated string will also be part of the data.
- Loading branch information
1 parent
0963609
commit 0404f75
Showing
2 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// NameData is a fixed-size type of 64 bytes. Using strlcpy to copy data into a | ||
// NameData struct can cause problems because any data that follows the initial | ||
// null-terminated string will also be part of the data. | ||
|
||
@rule_var_decl_struct@ | ||
symbol NAMEDATALEN; | ||
identifier I1, I2; | ||
@@ | ||
struct I1 | ||
{ | ||
... | ||
- char I2[NAMEDATALEN]; | ||
+ /* You are declaring a char of length NAMEDATALEN, please consider using NameData instead. */ | ||
+ NameData I2; | ||
... | ||
} | ||
|
||
@rule_namedata_strlcpy@ | ||
expression E1, E2; | ||
symbol NAMEDATALEN; | ||
@@ | ||
- strlcpy(E1, E2, NAMEDATALEN); | ||
+ /* You are using strlcpy with NAMEDATALEN, please consider using NameData and namestrcpy instead. */ | ||
+ namestrcpy(E1, E2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters