You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/08/16 16:01:52 UTC

[GitHub] [incubator-nuttx-apps] pkarashchenko commented on a diff in pull request #1280: apps: Fix the bug that setsockopt didn't check return value

pkarashchenko commented on code in PR #1280:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1280#discussion_r946972553


##########
netutils/webclient/webclient.c:
##########
@@ -1417,10 +1417,25 @@ int webclient_perform(FAR struct webclient_context *ctx)
                   tv.tv_sec  = ctx->timeout_sec;
                   tv.tv_usec = 0;
 
-                  setsockopt(conn->sockfd, SOL_SOCKET, SO_RCVTIMEO,
+                  /* Check return value one by one */
+
+                  ret = setsockopt(conn->sockfd, SOL_SOCKET, SO_RCVTIMEO,
                              (FAR const void *)&tv, sizeof(struct timeval));

Review Comment:
   ```suggestion
                     ret = setsockopt(conn->sockfd, SOL_SOCKET, SO_RCVTIMEO,
                                      (FAR const void *)&tv, sizeof(struct timeval));
   ```



##########
netutils/webclient/webclient.c:
##########
@@ -1417,10 +1417,25 @@ int webclient_perform(FAR struct webclient_context *ctx)
                   tv.tv_sec  = ctx->timeout_sec;
                   tv.tv_usec = 0;
 
-                  setsockopt(conn->sockfd, SOL_SOCKET, SO_RCVTIMEO,
+                  /* Check return value one by one */
+
+                  ret = setsockopt(conn->sockfd, SOL_SOCKET, SO_RCVTIMEO,
                              (FAR const void *)&tv, sizeof(struct timeval));
-                  setsockopt(conn->sockfd, SOL_SOCKET, SO_SNDTIMEO,
+                  if (ret != 0)
+                    {
+                      ret = -errno;
+                      nerr("ERROR: setsockopt failed: %d\n", ret);
+                      goto errout_with_errno;
+                    }
+
+                  ret = setsockopt(conn->sockfd, SOL_SOCKET, SO_SNDTIMEO,
                              (FAR const void *)&tv, sizeof(struct timeval));

Review Comment:
   ```suggestion
                     ret = setsockopt(conn->sockfd, SOL_SOCKET, SO_SNDTIMEO,
                                      (FAR const void *)&tv, sizeof(struct timeval));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org