Skip to content

Commit

Permalink
Added coccinelle rule to find strlcpy on NameData
Browse files Browse the repository at this point in the history
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
jnidzwetzki committed Feb 16, 2023
1 parent 0963609 commit 9db53b7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions coccinelle/namedata.cocci
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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_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);

0 comments on commit 9db53b7

Please sign in to comment.