Skip to content

Commit a29eed3

Browse files
committed
Linux netfilter: Avoid a Y2K38_SAFETY Coverity warning
It's about 'Sequence number' in Netlink messages. The Linux Documentation/userspace-api/netlink/intro.rst states: :c:member:`nlmsghdr.nlmsg_seq` should be a set to a monotonically increasing value. The value gets echoed back in responses and doesn't matter in practice, but setting it to an increasing value for each message sent is considered good hygiene. The purpose of the field is matching responses to requests. Thus seq_id, used to set it, has no need to be initialized to time(NULL). It can start at 1. The Coverity warning was: CID 1508935: Use of 32-bit time_t (Y2K38_SAFETY) A time_t value is stored in an integer with too few bits to accommodate it. The expression time(NULL) is cast to unsigned int. 356 seq_id = time(NULL); There was also an old clang warning on 64-bit build: pcap-netfilter-linux.c:356:12: warning: implicit conversion loses integer precision: 'time_t' (aka 'long') to 'unsigned int' [-Wshorten-64-to-32] 356 | seq_id = time(NULL); | ~ ^~~~~~~~~~ It was silenced by 16782c7. The "To be look at before 2038..." in the previous commit is no longer relevant.
1 parent 0056b3a commit a29eed3

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

pcap-netfilter-linux.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,6 @@ netfilter_send_config_msg(const pcap_t *handle, uint16_t msg_type, int ack, u_in
351351
struct sockaddr_nl snl;
352352
static unsigned int seq_id;
353353

354-
if (!seq_id)
355-
DIAG_OFF_NARROWING
356-
seq_id = time(NULL);
357-
DIAG_ON_NARROWING
358354
++seq_id;
359355

360356
nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nfgenmsg));

0 commit comments

Comments
 (0)