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

Format module incorrectly parses format string allowing to escape arguments #5973

Closed
vicuna opened this issue Apr 3, 2013 · 5 comments
Closed
Assignees

Comments

@vicuna
Copy link

@vicuna vicuna commented Apr 3, 2013

Original bug ID: 5973
Reporter: @let-def
Assigned to: @pierreweis
Status: closed (set by @xavierleroy on 2015-12-11T18:18:44Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.00.1
Category: standard library
Related to: #5380

Bug description

"@%s" format string when parsed by Format module breaks typing:
the @ escapes the following %s and the string argument won't be consumed at runtime, but the typer will still expect a string parameter.

Steps to reproduce

let _ = Format.(fprintf std_formatter "@%s%a" "" (fun _ _ -> ()) ())

Will execute "" as if it was a closure leading to unpredictable behavior, probably a segmentation fault.

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 3, 2013

Comment author: @gasche

That seems strongly related to #5380 . Do you have reproductibility information on which OCaml versions have the bug? Upto 4.00.1? Upto trunk?

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 3, 2013

Comment author: @let-def

Immediately reproducible with OCaml version 4.01.0+dev12-2013-03-28

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 16, 2013

Comment author: @gasche

There is some exciting work by Benoît Vaugon in preparation, that may obviate those petty runtime format bugs.

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 23, 2013

Comment author: @pierreweis

Thank you for filling a bug report.

Bug 5380 has been fixed and closed. I will investigate and correct this one ASAP.

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 23, 2013

Comment author: @pierreweis

Fixed in trunk and in 4.00.2+dev1. Old obsolete @ escape behaviour was still implemented in module Format. Weird.

Two remarks to conclude:
1 Your Format invocation has no semantics, since there is no pretty-printing box opened in your format string before any printing conversion specification.
2 As specified in the documentation, @ characters should be escaped in format strings for the Format module, otherwise the @ character must introduce a valid pretty printing indication. You should then write %@ instead of @ and open a box before printing. For instance, "@[%@%s%a@]" is a valid format string and should work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants