Skip to content

Commit 33d91ec

Browse files
committed
Linux netfilter: Fix a Y2K38_SAFETY Coverity warning
This concerns the '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. This commit is no longer useful. The "To be look at before 2038..." in the previous commit message is no longer relevant.
1 parent 0056b3a commit 33d91ec

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

pcap-netfilter-linux.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <config.h>
3232

3333
#include "pcap-int.h"
34-
#include "diag-control.h"
3534

3635
#include <errno.h>
3736
#include <stdlib.h>
@@ -351,10 +350,6 @@ netfilter_send_config_msg(const pcap_t *handle, uint16_t msg_type, int ack, u_in
351350
struct sockaddr_nl snl;
352351
static unsigned int seq_id;
353352

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

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

0 commit comments

Comments
 (0)