This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 282d4cb0e93925cc67ff449adfa553c4e23f89ad
Author: Abhishek Mishra <[email protected]>
AuthorDate: Thu Jul 16 18:55:41 2026 +0000

    libc/pwd: parse NuttX 5-field passwd records
    
    Accept user:hash:uid:gid:home lines produced by mkpasswd in addition
    to the six-field gecos form, and raise the default line buffer to 256.
    
    Signed-off-by: Abhishek Mishra <[email protected]>
---
 libs/libc/pwd/Kconfig            |  2 +-
 libs/libc/pwd/lib_find_pwdfile.c | 49 +++++++++++++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/libs/libc/pwd/Kconfig b/libs/libc/pwd/Kconfig
index 2fc6e0fbd54..88d5ba4e922 100644
--- a/libs/libc/pwd/Kconfig
+++ b/libs/libc/pwd/Kconfig
@@ -28,7 +28,7 @@ config LIBC_PASSWD_FILEPATH
 
 config LIBC_PASSWD_LINESIZE
        int "Maximum line size"
-       default 80
+       default 256
        ---help---
                The maximum length of one line in the passwd file.  This 
determines
                the size of the I/O buffer used to access the passwd file.
diff --git a/libs/libc/pwd/lib_find_pwdfile.c b/libs/libc/pwd/lib_find_pwdfile.c
index 97ac7abbfa1..88da93bbdac 100644
--- a/libs/libc/pwd/lib_find_pwdfile.c
+++ b/libs/libc/pwd/lib_find_pwdfile.c
@@ -170,14 +170,18 @@ static int pwd_foreach(pwd_foreach_match_t match, 
uintptr_t arg,
    *
    * The format of the password file is:
    *
-   *   user:x:uid:uid:geos:home
+   *   user:x:uid:gid:home
+   *
+   * Or the standard six-field form with an optional gecos field:
+   *
+   *   user:x:uid:gid:gecos:home
    *
    * Where:
    *   user:  User name
    *   x:     Encrypted password
    *   uid:   User ID
-   *   uid:   Group ID
-   *   geos:  User information
+   *   gid:   Group ID
+   *   gecos: User information (optional)
    *   home:  Login directory
    */
 
@@ -259,26 +263,45 @@ static int pwd_foreach(pwd_foreach_match_t match, 
uintptr_t arg,
       entry->pw_gid = (gid_t)atoi(save);
       save          = ptr;
 
-      /* Skip to the end of the user information and properly terminate it.
-       * The user information must be terminated with the field delimiter
-       * ':'.
+      /* NuttX passwd files use user:hash:uid:gid:home.  Standard passwd
+       * files may include an optional gecos field:
+       * user:hash:uid:gid:gecos:home
        */
 
-      for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
+      if (*ptr == ':')
         {
-        }
+          /* Skip to the end of the user information and properly terminate
+           * it.  The user information must be terminated with the field
+           * delimiter ':'.
+           */
 
-      if (*ptr == '\n' || *ptr == '\0')
+          for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
+            {
+            }
+
+          if (*ptr == '\n' || *ptr == '\0')
+            {
+              /* Bad line format? */
+
+              continue;
+            }
+
+          *ptr++          = '\0';
+          entry->pw_gecos = save;
+          entry->pw_dir   = ptr;
+        }
+      else if (*save != '\0' && *save != '\n')
+        {
+          entry->pw_gecos = "";
+          entry->pw_dir   = save;
+        }
+      else
         {
           /* Bad line format? */
 
           continue;
         }
 
-      *ptr++          = '\0';
-      entry->pw_gecos = save;
-      entry->pw_dir   = ptr;
-
       /* Skip to the end of the home directory and properly terminate it.
        * The home directory must be the last thing on the line.
        */

Reply via email to