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/12/18 08:02:29 UTC

[GitHub] [nuttx] xiaoxiang781216 opened a new pull request, #7912: net/local: Support the abstract path

xiaoxiang781216 opened a new pull request, #7912:
URL: https://github.com/apache/nuttx/pull/7912

   ## Summary
   And other minor change:
   
   - net/local: Return -EINVAL if the address length passed to local_bind is too small
   - net/local: Remove LOCAL_TYPE_UNTYPED
   
   ## Impact
   local socket, new functionality
   
   ## Testing
   Pass CI
   


-- 
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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051586712


##########
net/local/local_bind.c:
##########
@@ -58,43 +58,43 @@ int psock_local_bind(FAR struct socket *psock,
               unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
               addrlen >= sizeof(sa_family_t));
 
+  if (addrlen <= sizeof(sa_family_t))

Review Comment:
   let's remove the check



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051586316


##########
net/local/local_sockif.c:
##########
@@ -380,11 +380,12 @@ static int local_getsockname(FAR struct socket *psock,
 
           *addrlen = sizeof(sa_family_t);
         }
-      else /* conn->lctype = LOCAL_TYPE_PATHNAME */
+      else /* conn->lc_type = LOCAL_TYPE_PATHNAME */
         {
           /* Get the full length of the socket name (incl. null terminator) */
 
-          int namelen = strlen(conn->lc_path) + 1;
+          int namelen = strlen(conn->lc_path) + 1 +
+                        (conn->lc_type = LOCAL_TYPE_ABSTRACT);

Review Comment:
   ```suggestion
                           (conn->lc_type == LOCAL_TYPE_ABSTRACT);
   ```
   ?



##########
net/local/local_sockif.c:
##########
@@ -399,8 +400,15 @@ static int local_getsockname(FAR struct socket *psock,
 
           /* Copy the path into the user address structure */
 
-          strlcpy(unaddr->sun_path, conn->lc_path, namelen);
-          unaddr->sun_path[pathlen - 1] = '\0';
+          if (conn->lc_type = LOCAL_TYPE_ABSTRACT)

Review Comment:
   ```suggestion
             if (conn->lc_type == LOCAL_TYPE_ABSTRACT)
   ```



-- 
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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051587234


##########
net/local/local_bind.c:
##########
@@ -58,43 +58,43 @@ int psock_local_bind(FAR struct socket *psock,
               unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
               addrlen >= sizeof(sa_family_t));
 
+  if (addrlen <= sizeof(sa_family_t))

Review Comment:
   since th caller must specify a non-empty path.



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051587560


##########
net/local/local_bind.c:
##########
@@ -58,43 +58,43 @@ int psock_local_bind(FAR struct socket *psock,
               unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
               addrlen >= sizeof(sa_family_t));
 
+  if (addrlen <= sizeof(sa_family_t))

Review Comment:
   But then shouldn't it be `if (addrlen <= sizeof(sa_family_t)) + 1`?
   Or I misunderstand non-empty path?



-- 
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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051588651


##########
net/local/local_bind.c:
##########
@@ -58,43 +58,43 @@ int psock_local_bind(FAR struct socket *psock,
               unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
               addrlen >= sizeof(sa_family_t));
 
+  if (addrlen <= sizeof(sa_family_t))

Review Comment:
   Done.



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051591178


##########
net/local/local_connect.c:
##########
@@ -238,7 +238,9 @@ int psock_local_connect(FAR struct socket *psock,
 {
   FAR struct local_conn_s *client;
   FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
+  FAR const char *unpath = unaddr->sun_path;
   FAR struct local_conn_s *conn = NULL;

Review Comment:
   Not related to this PR, but seems that `NULL` init for `conn` is not needed.



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051589090


##########
net/local/local_bind.c:
##########
@@ -52,49 +52,47 @@ int psock_local_bind(FAR struct socket *psock,
   FAR struct local_conn_s *conn;
   FAR const struct sockaddr_un *unaddr =
     (FAR const struct sockaddr_un *)addr;
-  int namelen;
+  size_t namelen;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
-              unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
-              addrlen >= sizeof(sa_family_t));
+              unaddr != NULL && unaddr->sun_family == AF_LOCAL);
+
+  if (addrlen <= sizeof(sa_family_t) + 1)

Review Comment:
   Let's change to
   ```suggestion
     if (addrlen <= sizeof(sa_family_t) + 2)
   ```
   as it seems to be more correct since `unaddr->sun_path[1]` is accessed in `namelen == 0` case and `unaddr->sun_path` will contain at least 2 chars (1 non `'\0'` and one `'\0'`) if `namelen != 0`



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051589090


##########
net/local/local_bind.c:
##########
@@ -52,49 +52,47 @@ int psock_local_bind(FAR struct socket *psock,
   FAR struct local_conn_s *conn;
   FAR const struct sockaddr_un *unaddr =
     (FAR const struct sockaddr_un *)addr;
-  int namelen;
+  size_t namelen;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
-              unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
-              addrlen >= sizeof(sa_family_t));
+              unaddr != NULL && unaddr->sun_family == AF_LOCAL);
+
+  if (addrlen <= sizeof(sa_family_t) + 1)

Review Comment:
   Let's change to
   ```suggestion
     if (addrlen <= sizeof(sa_family_t) + 2)
   ```
   as it seems to be more correct since `unaddr->sun_path[1]` is accessed in `namelen == 0` case and `unaddr->sun_path` will contain at least 2 chars (1 non `'\0'` and one `'\0'`).



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051586990


##########
net/local/local_bind.c:
##########
@@ -58,43 +58,43 @@ int psock_local_bind(FAR struct socket *psock,
               unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
               addrlen >= sizeof(sa_family_t));
 
+  if (addrlen <= sizeof(sa_family_t))

Review Comment:
   Ok, but anyway, thy `<=` here and not `<`?



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051571488


##########
net/local/local_bind.c:
##########
@@ -58,43 +58,43 @@ int psock_local_bind(FAR struct socket *psock,
               unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
               addrlen >= sizeof(sa_family_t));
 
+  if (addrlen <= sizeof(sa_family_t))

Review Comment:
   how this co-exists with `addrlen >= sizeof(sa_family_t)` in `DEBUGASSERT` above?



-- 
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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051589021


##########
net/local/local_bind.c:
##########
@@ -55,46 +55,44 @@ int psock_local_bind(FAR struct socket *psock,
   int namelen;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
-              unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
-              addrlen >= sizeof(sa_family_t));
+              unaddr != NULL && unaddr->sun_family == AF_LOCAL);
+
+  if (addrlen <= sizeof(sa_family_t))
+    {
+      return -EINVAL;
+    }
 
   conn = (FAR struct local_conn_s *)psock->s_conn;
 
   /* Save the address family */
 
   conn->lc_proto = psock->s_type;
+  conn->lc_instance_id = -1;
 
   /* Now determine the type of the Unix domain socket by comparing the size
    * of the address description.
    */
 
-  if (addrlen == sizeof(sa_family_t))
+  namelen = strnlen(unaddr->sun_path, UNIX_PATH_MAX - 1);
+  if (namelen <= 0)

Review Comment:
   Done.



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051603845


##########
net/local/local_connect.c:
##########
@@ -238,7 +238,9 @@ int psock_local_connect(FAR struct socket *psock,
 {
   FAR struct local_conn_s *client;
   FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
+  FAR const char *unpath = unaddr->sun_path;
   FAR struct local_conn_s *conn = NULL;

Review Comment:
   Yes, but in such way the C standard would always init stack variables :)
   The init is needed if pointer is not unconditionally overwritten. In this case the init  is followed by explicit overwrite in `while ((conn = local_nextconn(conn)) != NULL)`, so initing is only wasting CPU cycles.



-- 
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


[GitHub] [nuttx] pkarashchenko merged pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko merged PR #7912:
URL: https://github.com/apache/nuttx/pull/7912


-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051589720


##########
net/local/local_bind.c:
##########
@@ -52,49 +52,47 @@ int psock_local_bind(FAR struct socket *psock,
   FAR struct local_conn_s *conn;
   FAR const struct sockaddr_un *unaddr =
     (FAR const struct sockaddr_un *)addr;
-  int namelen;
+  size_t namelen;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
-              unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
-              addrlen >= sizeof(sa_family_t));
+              unaddr != NULL && unaddr->sun_family == AF_LOCAL);
+
+  if (addrlen <= sizeof(sa_family_t) + 1)
+    {
+      return -EINVAL;
+    }
 
   conn = (FAR struct local_conn_s *)psock->s_conn;
 
   /* Save the address family */
 
   conn->lc_proto = psock->s_type;
+  conn->lc_instance_id = -1;
 
   /* Now determine the type of the Unix domain socket by comparing the size
    * of the address description.
    */
 
-  if (addrlen == sizeof(sa_family_t))
+  namelen = strnlen(unaddr->sun_path, UNIX_PATH_MAX - 1);
+  if (namelen == 0)

Review Comment:
   seems that `namelen` can be removed and  we can have faster operation with
   ```suggestion
     if (unaddr->sun_path[0] == '\0')
   ```



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051589331


##########
net/local/local_bind.c:
##########
@@ -52,49 +52,47 @@ int psock_local_bind(FAR struct socket *psock,
   FAR struct local_conn_s *conn;
   FAR const struct sockaddr_un *unaddr =
     (FAR const struct sockaddr_un *)addr;
-  int namelen;
+  size_t namelen;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
-              unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
-              addrlen >= sizeof(sa_family_t));
+              unaddr != NULL && unaddr->sun_family == AF_LOCAL);
+
+  if (addrlen <= sizeof(sa_family_t) + 1)

Review Comment:
   Seems I was too fast and condition is correct since `<=` handles both cases



-- 
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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051570647


##########
net/local/local_connect.c:
##########
@@ -238,7 +238,9 @@ int psock_local_connect(FAR struct socket *psock,
 {
   FAR struct local_conn_s *client;
   FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
+  FAR const char *unpath = unaddr->sun_path;
   FAR struct local_conn_s *conn = NULL;
+  local_type_e type = LOCAL_TYPE_PATHNAME;

Review Comment:
   Done.



##########
net/local/local_sockif.c:
##########
@@ -399,8 +400,15 @@ static int local_getsockname(FAR struct socket *psock,
 
           /* Copy the path into the user address structure */
 
-          strlcpy(unaddr->sun_path, conn->lc_path, namelen);
-          unaddr->sun_path[pathlen - 1] = '\0';
+          if (conn->lctype = LOCAL_TYPE_ABSTRACT)

Review Comment:
   Done.



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051586990


##########
net/local/local_bind.c:
##########
@@ -58,43 +58,43 @@ int psock_local_bind(FAR struct socket *psock,
               unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
               addrlen >= sizeof(sa_family_t));
 
+  if (addrlen <= sizeof(sa_family_t))

Review Comment:
   Ok, but anyway, why `<=` here and not `<`?



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051588481


##########
net/local/local_bind.c:
##########
@@ -55,46 +55,44 @@ int psock_local_bind(FAR struct socket *psock,
   int namelen;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
-              unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
-              addrlen >= sizeof(sa_family_t));
+              unaddr != NULL && unaddr->sun_family == AF_LOCAL);
+
+  if (addrlen <= sizeof(sa_family_t))
+    {
+      return -EINVAL;
+    }
 
   conn = (FAR struct local_conn_s *)psock->s_conn;
 
   /* Save the address family */
 
   conn->lc_proto = psock->s_type;
+  conn->lc_instance_id = -1;
 
   /* Now determine the type of the Unix domain socket by comparing the size
    * of the address description.
    */
 
-  if (addrlen == sizeof(sa_family_t))
+  namelen = strnlen(unaddr->sun_path, UNIX_PATH_MAX - 1);
+  if (namelen <= 0)

Review Comment:
   Also let's change type of `namelen` to `size_t`



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051587560


##########
net/local/local_bind.c:
##########
@@ -58,43 +58,43 @@ int psock_local_bind(FAR struct socket *psock,
               unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
               addrlen >= sizeof(sa_family_t));
 
+  if (addrlen <= sizeof(sa_family_t))

Review Comment:
   But then shouldn't it be `if (addrlen <= sizeof(sa_family_t) + 1)`?
   Or I misunderstand non-empty path?



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051603845


##########
net/local/local_connect.c:
##########
@@ -238,7 +238,9 @@ int psock_local_connect(FAR struct socket *psock,
 {
   FAR struct local_conn_s *client;
   FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
+  FAR const char *unpath = unaddr->sun_path;
   FAR struct local_conn_s *conn = NULL;

Review Comment:
   Yes, but in such way the C standard would always init stack variables :)
   The init is needed if pointer is not unconditionally overwritten. In this case the init  is followed by explicit overwrite in `while ((conn = local_nextconn(conn)) != NULL)`, so initing is only wasting CPU cycles.
   
   UPD: but seems I'm wrong as `conn` is passed as a parameter to `local_nextconn`, so init is needed for sure.



-- 
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


[GitHub] [nuttx] acassis commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051594340


##########
net/local/local_connect.c:
##########
@@ -238,7 +238,9 @@ int psock_local_connect(FAR struct socket *psock,
 {
   FAR struct local_conn_s *client;
   FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
+  FAR const char *unpath = unaddr->sun_path;
   FAR struct local_conn_s *conn = NULL;

Review Comment:
   @pkarashchenko is alls a good practice to NULL initialize pointers to avoid Dangling Pointer? https://en.wikipedia.org/wiki/Dangling_pointer



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051559141


##########
net/local/local_sockif.c:
##########
@@ -399,8 +400,15 @@ static int local_getsockname(FAR struct socket *psock,
 
           /* Copy the path into the user address structure */
 
-          strlcpy(unaddr->sun_path, conn->lc_path, namelen);
-          unaddr->sun_path[pathlen - 1] = '\0';
+          if (conn->lctype = LOCAL_TYPE_ABSTRACT)

Review Comment:
   ```suggestion
             if (conn->lc_type = LOCAL_TYPE_ABSTRACT)
   ```



##########
net/local/local_connect.c:
##########
@@ -238,7 +238,9 @@ int psock_local_connect(FAR struct socket *psock,
 {
   FAR struct local_conn_s *client;
   FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
+  FAR const char *unpath = unaddr->sun_path;
   FAR struct local_conn_s *conn = NULL;
+  local_type_e type = LOCAL_TYPE_PATHNAME;

Review Comment:
   ```suggestion
     enum local_type_e type = LOCAL_TYPE_PATHNAME;
   ```



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051587831


##########
net/local/local_bind.c:
##########
@@ -55,46 +55,44 @@ int psock_local_bind(FAR struct socket *psock,
   int namelen;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
-              unaddr != NULL && unaddr->sun_family == AF_LOCAL &&
-              addrlen >= sizeof(sa_family_t));
+              unaddr != NULL && unaddr->sun_family == AF_LOCAL);
+
+  if (addrlen <= sizeof(sa_family_t))
+    {
+      return -EINVAL;
+    }
 
   conn = (FAR struct local_conn_s *)psock->s_conn;
 
   /* Save the address family */
 
   conn->lc_proto = psock->s_type;
+  conn->lc_instance_id = -1;
 
   /* Now determine the type of the Unix domain socket by comparing the size
    * of the address description.
    */
 
-  if (addrlen == sizeof(sa_family_t))
+  namelen = strnlen(unaddr->sun_path, UNIX_PATH_MAX - 1);
+  if (namelen <= 0)

Review Comment:
   ```suggestion
     if (namelen == 0)
   ```



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051560015


##########
net/local/local_sockif.c:
##########
@@ -384,7 +384,8 @@ static int local_getsockname(FAR struct socket *psock,
         {
           /* Get the full length of the socket name (incl. null terminator) */
 
-          int namelen = strlen(conn->lc_path) + 1;
+          int namelen = strlen(conn->lc_path) + 1 +
+                        (conn->lctype = LOCAL_TYPE_ABSTRACT);

Review Comment:
   ```suggestion
                           (conn->lc_type = LOCAL_TYPE_ABSTRACT);
   ```



-- 
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


[GitHub] [nuttx] acassis commented on a diff in pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#discussion_r1051594340


##########
net/local/local_connect.c:
##########
@@ -238,7 +238,9 @@ int psock_local_connect(FAR struct socket *psock,
 {
   FAR struct local_conn_s *client;
   FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
+  FAR const char *unpath = unaddr->sun_path;
   FAR struct local_conn_s *conn = NULL;

Review Comment:
   @pkarashchenko isn't it always a good practice to NULL initialize pointers to avoid Dangling Pointer? https://en.wikipedia.org/wiki/Dangling_pointer



-- 
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


[GitHub] [nuttx] pkarashchenko commented on pull request #7912: net/local: Support the abstract path

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on PR #7912:
URL: https://github.com/apache/nuttx/pull/7912#issuecomment-1356806998

   @acassis would you please merge the PR if you are ok with the changes?


-- 
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