lclevy / ADFlib

A free, portable and open implementation of the Amiga filesystem
GNU General Public License v2.0
84 stars 29 forks source link

unadf improperly parses options with an argument #67

Closed t-w closed 5 months ago

t-w commented 7 months ago

2 issues have been found in the unadf command line option parser:

  1. unadf segfaults on invalid parameters
    
    $ unadf -v
    unADF v1.2 : a unzip like for .ADF files, powered by ADFlib (v0.8.0 - 2023-06-26)

Segmentation fault

$ unadf -d unADF v1.2 : a unzip like for .ADF files, powered by ADFlib (v0.8.0 - 2023-06-26)

Segmentation fault

(gdb) r Starting program: [...]/ADFlib/build/debug/examples/unadf -v [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". unADF v1.2 : a unzip like for .ADF files, powered by ADFlib (v0.8.0 - 2023-06-26)

Program received signal SIGSEGV, Segmentation fault. __strlen_sse2 () at ../sysdeps/x86_64/multiarch/strlen-sse2.S:142 142 ../sysdeps/x86_64/multiarch/strlen-sse2.S: No such file or directory. (gdb) bt

0 __strlen_sse2 () at ../sysdeps/x86_64/multiarch/strlen-sse2.S:142

1 0x00005555555a1f8d in __interceptor_strlen.part.0 ()

2 0x000055555565895f in parse_args (argc=2, argv=0x7fffffffde68)

at [...]/ADFlib/examples/unadf.c:199

3 0x00005555556580a4 in main (argc=2, argv=0x7fffffffde68)

at [...]/ADFlib/examples/unadf.c:94

-------
2. The argument given after the two options requiring an argument is (unexpectedly) used for both:

$ ../unadf -dv 0 ../tests/arccsh.adf unADF v1.2 : a unzip like for .ADF files, powered by ADFlib (v0.8.0 - 2023-06-26)

Device : Floppy DD. Cylinders = 80, Heads = 2, Sectors = 11. Volumes = 1 Volume : Floppy 880 KBytes, "cshell" between sectors [0-1759]. OFS. Filled at 75.2%. x - 0/c/ x - 0/c/Format x - 0/c/Mount x - 0/c/Zip x - 0/c/Type x - 0/c/DMS x - 0/c/cmd.txt x - 0/c/UNLZX x - 0/c/Relabel x - 0/c/Info x - 0/c/CPU x - 0/c/Assign x - 0/c/Deksid x - 0/c/List x - 0/c/transdisk x - 0/c/LhA x - 0/c/LoadWB x - 0/c/LZX x - 0/l/ x - 0/l/LZX.Keyfile x - 0/devs/ x - 0/devs/DOSDrivers/ x - 0/devs/DOSDrivers/SD0.info x - 0/devs/DOSDrivers/SD0 x - 0/devs/statram.device x - 0/devs/SyStEm-CoNfIgUrAtIoN x - 0/s/ x - 0/s/.cshrc x - 0/s/aliases x - 0/s/.login x - 0/s/startup-sequence x - 0/libs/ x - 0/libs/arp.library x - 0/libs/asl.library x - 0/libs/diskfont.library x - 0/CSH x - 0/LoadWB x - 0/system-configuration

$ ls 0

$ ls 0 c CSH devs l libs LoadWB s system-configuration



* Both to fix.
t-w commented 7 months ago

@kyz, would you find a moment to have a look a this?

(We should fix this for the next release that is planned rather soon...).

t-w commented 7 months ago

Actually, for 2 we have:

unADF v1.2 : a unzip like for .ADF files, powered by ADFlib (v0.8.0 - 2023-06-26)

Device : Floppy DD. Cylinders = 80, Heads = 2, Sectors = 11. Volumes = 1
Volume : Floppy 880 KBytes, "cshell" between sectors [0-1759]. OFS. Filled at 75.2%.
x - 3/c/
x - 3/c/Format
x - 3/c/Mount
x - 3/c/Zip
x - 3/c/Type
x - 3/c/DMS
x - 3/c/cmd.txt
x - 3/c/UNLZX
x - 3/c/Relabel
x - 3/c/Info
x - 3/c/CPU
x - 3/c/Assign
x - 3/c/Deksid
x - 3/c/List
x - 3/c/transdisk
x - 3/c/LhA
x - 3/c/LoadWB
x - 3/c/LZX
x - 3/l/
x - 3/l/LZX.Keyfile
x - 3/devs/
x - 3/devs/DOSDrivers/
x - 3/devs/DOSDrivers/SD0.info
x - 3/devs/DOSDrivers/SD0
x - 3/devs/statram.device
x - 3/devs/SyStEm-CoNfIgUrAtIoN
x - 3/s/
x - 3/s/.cshrc
x - 3/s/aliases
x - 3/s/.login
x - 3/s/startup-sequence
x - 3/libs/
x - 3/libs/arp.library
x - 3/libs/asl.library
x - 3/libs/diskfont.library
x - 3/CSH
x - 3/LoadWB
x - 3/system-configuration

so v (volume) silently becomes 0.

These options should rather be only allowed to be given separately - where they work fine (except 1.):

$ ../unadf -d 4 -v 3 ../tests/arccsh.adf
unADF v1.2 : a unzip like for .ADF files, powered by ADFlib (v0.8.0 - 2023-06-26)

Device : Floppy DD. Cylinders = 80, Heads = 2, Sectors = 11. Volumes = 1
../tests/arccsh.adf: volume 3 is invalid (device has 1 volume(s))