The length of tldl_reason is TCP_LOG_REASON_LEN, not TCP_LOG_ID_LEN. No functional change intended.
Reported by: Coverity Scan
CID: 1418074
CID: 1418276
Differential D44510
tcp bblog: use correct length tuexen on Mar 26 2024, 12:20 PM. Authored by Tags None Referenced Files
Details The length of tldl_reason is TCP_LOG_REASON_LEN, not TCP_LOG_ID_LEN. No functional change intended. Reported by: Coverity Scan
Diff Detail
Event TimelineComment Actions A sidenote: nginx practice to prevent this kind of bugs is this: strlcpy(entry->tldl_reason, "UNKNOWN", sizeof("UNKNOWN")); I would suggest to further improve this: #define STRWSIZE0(s) #s, sizeof(#s) #define STRWSIZE(s) #s, sizeof(#s) - 1 to prevent probability of typing a long string twice differently. Comment Actions I am confused: isn't the last parameter of strlcpy the size of the destination buffer, not the length of the source. So if you write something like strlcpy(entry->tldl_reason, "This string is much longer than the buffer size of thirtytwo bytes", sizeof("This string is much longer than the buffer size of thirtytwo bytes")); will result in a buffer overflow. strlcpy(entry->tldl_reason, "This string is much longer than the buffer size of thirtytwo bytes", TCP_LOG_REASON_LEN); would truncate the string correctly and assure that tldl_reason is NUL terminated.
Comment Actions Yes, probably this particular strlcpy() was not the best example. We will write the correct length of the source string, though. For the destination size check this technique requires an additional static assert, that would at compile time check that every possible static string ever written to this destination is smaller or equal than destination. |