Re: [PATCH 1/1] rev: handle cases where lines are too long for buffer

2021-08-09 Thread Clayton Craft
On Mon, 09 Aug 2021 21:57:00 +0100 Ron Yorston  wrote:
> Or how about this?
> 
> Ron
> ---
>  util-linux/rev.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/util-linux/rev.c b/util-linux/rev.c
> index d439b4da8..63b005c67 100644
> --- a/util-linux/rev.c
> +++ b/util-linux/rev.c
> @@ -109,6 +109,7 @@ int rev_main(int argc UNUSED_PARAM, char **argv)
>   strrev(buf, strlen(buf));
>  #endif
>   fputs_stdout(buf);
> + pos = 0;

Yeah... that also seems to fix it, and is obviously less intrusive/crazy than
the thing I sent.

-Clayton


signature.asc
Description: PGP signature
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH 1/1] rev: handle cases where lines are too long for buffer

2021-08-09 Thread Ron Yorston
Or how about this?

Ron
---
 util-linux/rev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/util-linux/rev.c b/util-linux/rev.c
index d439b4da8..63b005c67 100644
--- a/util-linux/rev.c
+++ b/util-linux/rev.c
@@ -109,6 +109,7 @@ int rev_main(int argc UNUSED_PARAM, char **argv)
strrev(buf, strlen(buf));
 #endif
fputs_stdout(buf);
+   pos = 0;
}
fclose(fp);
} while (*argv);
-- 
2.31.1

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH 0/1] rev: fix bug with long multi-line input

2021-08-09 Thread Clayton Craft
The bug mentioned in the patch can be reproduced using this as input:
---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+
abc

$ busybox rev < input.txt
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
cba---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+

util-linux's rev:
$ rev < input.txt
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
cba

As an aside, I tried to report this to bugzilla but recieved the
following error:
Invalid Content-Type 'subtype' parameter at Bugzilla/BugMail.pm line 471.


Clayton Craft (1):
  rev: handle cases where lines are too long for buffer

 util-linux/rev.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

-- 
2.32.0

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH 1/1] rev: handle cases where lines are too long for buffer

2021-08-09 Thread Clayton Craft
This fixes a problem where the contents of the previous line were output
when the previous line was long enough to cause buf to be extended.
The buffer is re-used/rewritten for each line, instead of appending to it.
---
 util-linux/rev.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/util-linux/rev.c b/util-linux/rev.c
index d439b4da8..53b6b91aa 100644
--- a/util-linux/rev.c
+++ b/util-linux/rev.c
@@ -78,20 +78,21 @@ int rev_main(int argc UNUSED_PARAM, char **argv)
pos = 0;
while (1) {
/* Read one line */
-   buf[bufsize - 1] = 1; /* not 0 */
-   if (!fgets(buf + pos, bufsize - pos, fp))
+   if (!fgets(buf, bufsize, fp))
break; /* EOF/error */
-   if (buf[bufsize - 1] == '\0' /* fgets filled entire 
buffer */
-&& buf[bufsize - 2] != '\n' /* and did not read '\n' */
+   int len = strlen(buf);
+   while (buf[len - 1] != '\n' /* fgets filled entire 
buffer */
 && !feof(fp)
) {
/* Line is too long, extend buffer */
pos = bufsize - 1;
bufsize += 64 + bufsize / 8;
buf = xrealloc(buf, bufsize);
-   continue;
+   /* Fill remaining buffer */
+   if (!fgets(buf + pos, bufsize - pos, fp))
+   break;
+   len = strlen(buf);
}
-
/* Process and print it */
 #if ENABLE_UNICODE_SUPPORT
{
-- 
2.32.0

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: Curious bug in remounting read-only cdrom mount point

2021-08-09 Thread Roberto A. Foglietta
Il giorno lun 9 ago 2021 alle ore 15:55 Lauri Kasanen  ha
scritto:

> Hi,
>
> Your logs show you're running a different binary. correct.txt and
> dropbear.txt run the util-linux mount, and only uncorrect.txt runs
> busybox mount.
>
> So it's not about SSH or the env, but looks like busybox mount just has
> a different (wrong?) return code.
>

Hi Lauri,

 you are right the environment is different, so different binaries are
called.
 Yes, the problem is related to mount exit status which is wrong.

root@box:~# which mount
/bin/mount
root@box:~# ls -la /bin/mount
lrwxrwxrwx1 root root12 Aug  9 17:52 /bin/mount ->
busybox.suid
root@box:~# mount -o remount,rw /mnt/sr0; echo $?
0

 Thank you,
--
Roberto A. Foglietta
+39.349.33.30.697
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: Curious bug in remounting read-only cdrom mount point

2021-08-09 Thread Lauri Kasanen
Hi,

Your logs show you're running a different binary. correct.txt and
dropbear.txt run the util-linux mount, and only uncorrect.txt runs
busybox mount.

So it's not about SSH or the env, but looks like busybox mount just has
a different (wrong?) return code.

- Lauri
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: Curious bug in remounting read-only cdrom mount point

2021-08-09 Thread Roberto A. Foglietta
Il giorno lun 9 ago 2021 alle ore 08:06 Roberto A. Foglietta <
roberto.foglie...@gmail.com> ha scritto:

> Hi all,
>
>  I found a corious bug in remounting a read-only cdrom mount point in
> busybox v1.33.0.
>

[...]

I am attaching the strace log for the two cases plus a third done with
dropbear.
Surprisingly, using dropbear as a SSH server the problem does not arise

on ssh opened shell: correct.txt
strace mount -o remount,rw /mnt/sr0 2>correct.txt; echo $?

on ssh connection: uncorrect.txt
ssh root@10.0.2.17 'strace mount -o remount,rw /mnt/sr0 2>uncorrect.txt;
echo $?'

using dropbear as ssh server: dropbear.txt
ssh root@10.0.2.17 'strace mount -o remount,rw /mnt/sr0 2>dropbear.txt;
echo $?'

 TO ADD STRACE  

tinycore/provides/tcprovides.sh bin/strace
tinycore/provides/tcdownload.sh strace.tcz
mv strace.tcz tinycore/tcz
./make.sh qemu-test iso

Adding dropbear is similar but it should be launched by hand.

 Cheers,
-- 
Roberto A. Foglietta
+39.349.33.30.697
execve("/usr/local/bin/mount", ["mount", "-o", "remount,rw", "/mnt/sr0"], 
0x7fff51e20c68 /* 21 vars */) = 0
brk(NULL)   = 0x117f000
access("/etc/ld.so.preload", R_OK)  = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=5728, ...}) = 0
mmap(NULL, 5728, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7f5997f000
close(3)= 0
openat(AT_FDCWD, "/usr/local/lib/libmount.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\332\0\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=317456, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f7f5997d000
mmap(NULL, 320328, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7f5992e000
mprotect(0x7f7f5993a000, 262144, PROT_NONE) = 0
mmap(0x7f7f5993a000, 188416, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xc000) = 0x7f7f5993a000
mmap(0x7f7f59968000, 69632, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 
0x3a000) = 0x7f7f59968000
mmap(0x7f7f5997a000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4b000) = 0x7f7f5997a000
mmap(0x7f7f5997c000, 840, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7f5997c000
close(3)= 0
openat(AT_FDCWD, "/lib/libblkid.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\256\0\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=275312, ...}) = 0
mmap(NULL, 278184, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7f598ea000
mmap(0x7f7f598f4000, 155648, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa000) = 0x7f7f598f4000
mmap(0x7f7f5991a000, 61440, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 
0x3) = 0x7f7f5991a000
mmap(0x7f7f59929000, 20480, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3e000) = 0x7f7f59929000
close(3)= 0
openat(AT_FDCWD, "/lib/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260#\0\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=31584, ...}) = 0
mmap(NULL, 35808, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7f598e1000
mmap(0x7f7f598e3000, 12288, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f7f598e3000
mmap(0x7f7f598e6000, 8192, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 
0x5000) = 0x7f7f598e6000
mmap(0x7f7f598e8000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f7f598e8000
close(3)= 0
openat(AT_FDCWD, "/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0~-\2\0\0\0\0\0"..., 832) 
= 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1573080, ...}) = 0
mmap(NULL, 1586608, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7f5975d000
mprotect(0x7f7f5977f000, 1409024, PROT_NONE) = 0
mmap(0x7f7f5977f000, 1101824, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f7f5977f000
mmap(0x7f7f5988c000, 303104, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 
0x12f000) = 0x7f7f5988c000
mmap(0x7f7f598d7000, 24576, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x179000) = 0x7f7f598d7000
mmap(0x7f7f598dd000, 13744, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7f598dd000
close(3)= 0
openat(AT_FDCWD, "/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\371j\0\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=97568, ...}) = 0
mmap(NULL, 115792, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7f5974
mmap(0x7f7f59746000, 49152, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f7f59746000
mmap(0x7f7f59752000, 20480, 

Curious bug in remounting read-only cdrom mount point

2021-08-09 Thread Roberto A. Foglietta
Hi all,

 I found a corious bug in remounting a read-only cdrom mount point in
busybox v1.33.0.
 Possibly the bug stays also in previous and later versions.
 These are the instructions to reproduce the bug in a easy way:

wget
https://github.com/robang74/tinycore-editor/archive/refs/tags/v0.3.8.tar.gz
tar xzf v0.3.8.tar.gz
cd tinycore-editor-0.3.8
tinycore/provides/tcgetdistro.sh

### configure your qemu ip addresses 

ifconfig eth0 | grep "inet "
#   inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
echo "
netm=24
myip=10.0.2.15
brip=10.0.2.16
tcip=10.0.2.17
" > make.conf

#

./make.sh qemu-test iso

this command above launch qemu, wait for sshd and open a ssh session in the
console

in ssh: mount -o remount,rw /mnt/sr0; echo $? # error: 32, OK
in qemu: mount -o remount,rw /mnt/sr0; echo $? # error: 32, OK

exit by ssh session, return to the console and do this

ssh root@10.0.2.17 'mount -o remount,rw /mnt/sr0; echo $?' #0

This command above returns an unexpected exit status: 0 instead of 32.

ssh root@10.0.2.17 'false; echo $?' # error: 1, OK

 This last command is only a counter-proof of the error status.

 I hope this helps,
-- 
Roberto A. Foglietta
+39.349.33.30.697
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox