Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cksum: Check --length before --check #7050

Closed
RenjiSann opened this issue Jan 2, 2025 · 5 comments · Fixed by #7071
Closed

cksum: Check --length before --check #7050

RenjiSann opened this issue Jan 2, 2025 · 5 comments · Fixed by #7071
Labels

Comments

@RenjiSann
Copy link
Contributor

(Found with fuzzer)

args: ["cksum", "-l", "158", "-c", "-a", "crc", "/tmp/shlsgiqaxn"]                                                                                                                                                                                                                          
Running test ["cksum", "-l", "158", "-c", "-a", "crc", "/tmp/shlsgiqaxn"]                                                                                                                                                                                                                   
Test Type: cksum                                                                                                                                                                                                                                                                            
Input: ["-l", "158", "-c", "-a", "crc", "/tmp/shlsgiqaxn"]                                                                                                                                                                                                                                  
Rust stderr: --check is not supported with --algorithm={bsd,sysv,crc}                                                                                                                                                                                                                       
GNU stderr: --length is only supported with --algorithm=blake2b                                                                                                                                                                                                                             
Diff=                                                                                                                                                                                                                                                                                       
---check is not supported with --algorithm={bsd,sysv,crc}                                                                                                                                                                                                                                   
+--length is only supported with --algorithm=blake2b                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                            
Discrepancy detected: stderr differs                                                                                                                                                                                                                                                        
Test completed with discrepancies for cksum: ["-l", "158", "-c", "-a", "crc", "/tmp/shlsgiqaxn"]

Basically, cksum should check that --length is allowed before checking if --check is.

@RenjiSann
Copy link
Contributor Author

@sylvestre this can be set as a good first issue IMO

@Felle33
Copy link
Contributor

Felle33 commented Jan 3, 2025

Hello, I would like to solve this issue, although it is the first time I contribute to open source projects (so sorry in advance if I make some mistakes). I read the DEVELOPMENT.md and CONTRIBUTING.md files and followed the guidelines to install the environment.
I would like to reproduce the bug, but I am not sure how to do it.

@RenjiSann
Copy link
Contributor Author

Hello, I would like to solve this issue, although it is the first time I contribute to open source projects (so sorry in advance if I make some mistakes). I read the DEVELOPMENT.md and CONTRIBUTING.md files and followed the guidelines to install the environment. I would like to reproduce the bug, but I am not sure how to do it.

Hi @Felle33 ! thanks for being interested in fixing this.
The steps to reproduce the error are simple. There is basically no preparation work other than building the cksum util.
To do so, you can figure out the cargo command, but I never remember it and I personnally use the make wrapper to do it

make UTILS="cksum"

Once done, your cksum binary will be at target/debug/cksum.

You should observe the following behavior when running it with the problematic arguments

./target/debug/cksum -l 158 -c -a crc /tmp/xxx
--check is not supported with --algorithm={bsd,sysv,crc}

Note: The /tmp/xxx file content or existence actually doesn't matter because flag sanitization happens before file checking.

Now, you can compare this to the GNU cksum. You may use your OS' coreutils if it's the version 9.5, which is the version we're trying to match in uutils (check this with cksum --version). Otherwise, you will need to run the script ./util/build-gnu.sh and follow its instructions to build the GNU cksum binary from source (IIRC, once built, you will find the binary at ../gnu/src/cksum).
With GNU's implementation, you should observe the following behavior when running it with the problematic arguments:

./target/debug/cksum -l 158 -c -a crc /tmp/xxx
--length is only supported with --algorithm=blake2b

I hope that's detailed enough for you, feel free to reach out to me here on the issue, or on the discord server if you have any other question regarding your development environment ^^

@cakebaker
Copy link
Contributor

@RenjiSann good explanation :)

@Felle33
Copy link
Contributor

Felle33 commented Jan 4, 2025

@RenjiSann thanks for the support :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants