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

fuzzing on date: date -I @ triggers a panic #4494

Closed
sylvestre opened this issue Mar 11, 2023 · 6 comments · Fixed by #4499
Closed

fuzzing on date: date -I @ triggers a panic #4494

sylvestre opened this issue Mar 11, 2023 · 6 comments · Fixed by #4499
Labels

Comments

@sylvestre
Copy link
Contributor

Found with the fuzzer introduced in #4389

$ ../target/debug/coreutils date -I@
thread 'main' panicked at 'Invalid format: @', src/uu/date/src/date.rs:118:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@sylvestre sylvestre changed the title fuzzing on date: target/debug/coreutils date -I @ triggers a panic fuzzing on date: date -I @ triggers a panic Mar 11, 2023
@shanmukhateja
Copy link
Contributor

I ran the same on GNU date and I see this.

$ date -I@
date: invalid argument ‘@’ for ‘--iso-8601’
Valid arguments are:
  - ‘hours’
  - ‘minutes’
  - ‘date’
  - ‘seconds’
  - ‘ns’
Try 'date --help' for more information.

@sylvestre What should the correct response be in this case?

@sylvestre
Copy link
Contributor Author

at least

date:` invalid argument ‘@’ for ‘--iso-8601’

would be great

@shanmukhateja
Copy link
Contributor

So do I just update the String in panic! or is there a something more you'd like me to add?

@sylvestre
Copy link
Contributor Author

I think you need to handle the error properly

@shanmukhateja
Copy link
Contributor

@sylvestre I noticed the panic is placed inside the impl for Iso8601Format enum. I went ahead and updated the error message to look like GNU's date.

After the change, the output is as follows:

Failed case:

$ target/debug/date -I@    
thread 'main' panicked at 'date:` invalid argument `@` for '--iso-8601'', src/uu/date/src/date.rs:118:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Success case:

target/debug/date -Ihours
2023-03-12T11+05:30

@tertsdiepraam
Copy link
Member

Note that the comment on this panic says that this case should have been handled by clap, but it wasn't. So probably we need to add a value parser to the argument in clap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants