[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-wget] Recommendations for adding log statements after checking sets

From: niuxu
Subject: [Bug-wget] Recommendations for adding log statements after checking setsockopt()
Date: Mon, 15 Oct 2018 11:15:54 +0800 (GMT+08:00)

Our team works on enhance logging practices by learning from historical log 
revisions in evolution.
We find that 2 patches have added validation code about the return value of 
setsockopt() along with logging statements. 

So we suggest that the return value of setsockopt() should be checked and 
logged if the check pass.

And, we find 1 missed spot in line 35 of wget-1.19.2/lib/setsockopt.c:
rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t 
  if (level == SOL_SOCKET
      && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
        const struct timeval *tv = optval;
        int milliseconds = tv->tv_sec * 1000 + tv->tv_usec / 1000;
        optval = &milliseconds;
        r = setsockopt (sock, level, optname, optval, sizeof (int));
        r = setsockopt (sock, level, optname, optval, optlen);
  if (r < 0)
     set_winsock_errno ();

  return r;

And the 2 patches that support us are:
1) In line 334 of File: wget-1.18/src/connect.c
     if (opt.limit_rate && opt.limit_rate < 8192)
       int bufsize = opt.limit_rate;
       if (bufsize < 512)
         bufsize = 512;          /* avoid pathologically small values */
     #ifdef SO_RCVBUF
-      setsockopt (sock, SOL_SOCKET, SO_RCVBUF,
-                  (void *)&bufsize, (socklen_t)sizeof (bufsize));
+      if (setsockopt (sock, SOL_SOCKET, SO_RCVBUF,
+                  (void *) &bufsize, (socklen_t) sizeof (bufsize)))
+        logprintf (LOG_NOTQUIET, _("setsockopt SO_RCVBUF failed: %s\n"),
+                   strerror (errno));

2) In line 474 of File:  wget-1.18/src/connect.c
   sock = socket (bind_address->family, SOCK_STREAM, 0);
   if (sock < 0)
     return -1;
-  setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, setopt_ptr, setopt_size);
+  if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, setopt_ptr, setopt_size))
+    logprintf (LOG_NOTQUIET, _("setsockopt SO_REUSEADDR failed: %s\n"),
+               strerror (errno));

Thanks for your reading and we are looking forward to your reply about the 
correctness of our suggestion.
May you a good day! ^^

Best Regards,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]