Use a bigger buffer on stack for getmntent_r so we can handle entries
with lines longer that 504 chars.

This solves issue when running `mount -o remount,rw ...` in a docker
container on Fedora 43.

ref: https://github.com/k0sproject/k0s/issues/6774
ref: https://lists.busybox.net/pipermail/busybox/2025-December/091859.html

function                                             old     new   delta
mount_main                                          1402    1401      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-1)               Total: -1 bytes
   text    data     bss     dec     hex filename
 824613   14092    1864  840569   cd379 busybox_old
 824612   14092    1864  840568   cd378 busybox_unstripped

Signed-off-by: Natanael Copa <[email protected]>
---
 util-linux/mount.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/util-linux/mount.c b/util-linux/mount.c
index d0f0ae1ad..c0db67ce4 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -2283,6 +2283,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
        unsigned long cmdopt_flags;
        unsigned opt;
        struct mntent mtpair[2], *mtcur = mtpair;
+       char buf[GETMNTENT_BUFSIZE * 2];
        IF_NOT_DESKTOP(const int nonroot = 0;)
 
        IF_DESKTOP(int nonroot = ) sanitize_env_if_suid();
@@ -2395,9 +2396,9 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
                struct mntent *mtother = (mtcur==mtpair ? mtpair+1 : mtpair);
 
                // Get next fstab entry
-               if (!getmntent_r(fstab, mtcur, getmntent_buf
-                                       + (mtcur==mtpair ? GETMNTENT_BUFSIZE/2 
: 0),
-                               GETMNTENT_BUFSIZE/2)
+               if (!getmntent_r(fstab, mtcur, buf
+                                       + (mtcur==mtpair ? GETMNTENT_BUFSIZE : 
0),
+                               GETMNTENT_BUFSIZE)
                ) { // End of fstab/mtab is reached
                        mtcur = mtother; // the thing we found last time
                        break;
-- 
2.52.0

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to