You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "casaroli (via GitHub)" <gi...@apache.org> on 2026/10/11 18:56:58 UTC

[PR] fs/vfs: Return the length that the file system gives from readlink(). [nuttx]

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

   ## Summary
   
   `readlink()` of a path in a mounted file system returned `strlen()` of the buffer. The `readlink` method of a file system, like `readlink()` itself, returns the number of bytes it placed and does not add a null byte, so `strlen()` read past the target into old buffer contents and the caller got a wrong length.
   
   This PR returns the length that the file system gives. `readlink()` of a pseudo-file-system link is not changed.
   
   ## Impact
   
   `readlink()` on mounted file systems that implement `readlink` (hostfs, rpmsgfs, and v9fs with the companion PR) returns the right length.
   
   ## Testing
   
   The run-time tests ran on a local branch that has this change and other pending changes on top of master; the builds are of this branch alone.
   
   qemu-armv8a, kernel build, QEMU 11 with HVF, a 9P share with v9fs `readlink()` (companion PR): `readlink flink dlink uplink` printed `d/sub/f.txt`, `d` and `../lt/d/sub/f.txt` followed by stray bytes from the buffer before; after, it prints exactly the three targets.
   
   Builds with `-Wno-cpp -Werror`: `qemu-armv8a:netnsh`, `qemu-armv8a:nsh` with `CONFIG_FS_LINKS=y`, `lm3s6965-ek:qemu-flat`. `tools/checkpatch.sh -c -u -m -g` passes.
   


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


Re: [PR] fs/vfs: Return the length that the file system gives from readlink(). [nuttx]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #20592:
URL: https://github.com/apache/nuttx/pull/20592#issuecomment-6112591400

   <!-- membrowse-pr-comment -->
   ## <img src="https://membrowse.com/membrowse-logo.svg" height="24" align="top"> MemBrowse Memory Report
   
   *No memory changes detected for:*
   - [arduino-mega2560](https://membrowse.com/public/apache/nuttx/target/arduino-mega2560/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   - [esp32-devkitc](https://membrowse.com/public/apache/nuttx/target/esp32-devkitc/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   - [hifive1-revb](https://membrowse.com/public/apache/nuttx/target/hifive1-revb/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   - [mirtoo](https://membrowse.com/public/apache/nuttx/target/mirtoo/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   - [qemu-armv8a](https://membrowse.com/public/apache/nuttx/target/qemu-armv8a/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   - [qemu-intel64](https://membrowse.com/public/apache/nuttx/target/qemu-intel64/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   - [rx65n-rsk2mb](https://membrowse.com/public/apache/nuttx/target/rx65n-rsk2mb/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   - [s698pm-dkit](https://membrowse.com/public/apache/nuttx/target/s698pm-dkit/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   - [stm32-nucleo-f103rb](https://membrowse.com/public/apache/nuttx/target/stm32-nucleo-f103rb/compare?head=eaad453f1b6ee16921b41c1a3bca85f7f759eba3&base=4bc1ab2fd7bede547e91c8e3a7dac3bd6eb941f7)
   


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


Re: [PR] fs/vfs: Return the length that the file system gives from readlink(). [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #20592:
URL: https://github.com/apache/nuttx/pull/20592#discussion_r4244022890


##########
fs/vfs/fs_readlink.c:
##########
@@ -138,13 +141,14 @@ ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize)
       /* Copy the link target path to the user-provided buffer. */
 
       strlcpy(buf, node->u.i_link, bufsize);

Review Comment:
   nread = strlcpy(...);
   nread = MIN(nread, bufsize);



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


Re: [PR] fs/vfs: Return the length that the file system gives from readlink(). [nuttx]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on code in PR #20592:
URL: https://github.com/apache/nuttx/pull/20592#discussion_r4248100341


##########
fs/vfs/fs_readlink.c:
##########
@@ -138,13 +141,14 @@ ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize)
       /* Copy the link target path to the user-provided buffer. */
 
       strlcpy(buf, node->u.i_link, bufsize);

Review Comment:
   Done, thanks.



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


Re: [PR] fs/vfs: Return the length that the file system gives from readlink(). [nuttx]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #20592:
URL: https://github.com/apache/nuttx/pull/20592


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