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

Scanf ignores possitional parameters parsing format strings... #4321

Closed
vicuna opened this issue Jun 20, 2007 · 3 comments
Closed

Scanf ignores possitional parameters parsing format strings... #4321

vicuna opened this issue Jun 20, 2007 · 3 comments
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Jun 20, 2007

Original bug ID: 4321
Reporter: till
Assigned to: @pierreweis
Status: closed (set by @damiendoligez on 2008-09-10T15:35:23Z)
Resolution: fixed
Priority: normal
Severity: crash
Version: 3.10.0
Fixed in version: 3.11+dev
Category: ~DO NOT USE (was: OCaml general)
Related to: #3992
Monitored by: jm @mmottl

Bug description

Scanf.sscanf ""%2$s %1$i"" "%{%s %i%}" (fun _ -> ());;

doesn't raise any exception while:

Scanf.sscanf ""%2$i %1$s"" "%{%s %i%}" (fun _ -> ());;

raises one....

Additional information

I consider this bug to be critical since it can be exploited in some application to cause ocaml to segfault, for instance, in i18n it is frequent to get format strings from separate files...

consider:

let f s = Scanf.sscanf s "Toto %{%c %s%}" (fun f ->Printf.printf f 'x' "123");;
let _ = f "Toto "%2$c=%1$s"";;

@vicuna
Copy link
Author

vicuna commented Jun 21, 2007

Comment author: @Chris00

Related to bug #3992

@vicuna
Copy link
Author

vicuna commented Nov 9, 2007

Comment author: @pierreweis

According to its documentation, the Scanf module is not supposed to accept any positional parameters specification in the format strings. So, raising an exception is the correct and expected behaviour.

Indeed, the static type-checker also rejects positional parameters, as examplify here:

format_of_string "%1$s";;

Bad conversion %$, at char number 0 in format string ``%1$s''

Despite those checks, your example leads to the production of a format string value with positional parameters in it, by-passing the typechecker checks and the Scanf checks! This is due to a bug in the function that performs the dynamic type-checking verification for format strings which I will correct very soon.

@vicuna
Copy link
Author

vicuna commented Sep 10, 2008

Comment author: @damiendoligez

Quick fix: remove positional parameters in printf/scanf. They will come back when we manage to make them work perfectly.

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

No branches or pull requests

2 participants