Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004321OCaml~DO NOT USE (was: OCaml general)public2007-06-20 19:532008-09-10 17:35
Assigned Toweis 
PlatformOSOS Version
Product Version3.10.0 
Target VersionFixed in Version3.11+dev 
Summary0004321: Scanf ignores possitional parameters parsing format strings...
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 InformationI 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...


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

- Relationships
related to 0003992closedweis Printf: positional specifiers do not work 

-  Notes
Christophe Troestler (reporter)
2007-06-21 19:21

Related to bug 0003992
weis (developer)
2007-11-09 17:26

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.
doligez (administrator)
2008-09-10 17:35

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

- Issue History
Date Modified Username Field Change
2007-06-20 19:53 till New Issue
2007-06-21 19:21 Christophe Troestler Note Added: 0004094
2007-11-09 17:08 weis Description Updated
2007-11-09 17:26 weis Note Added: 0004251
2007-11-09 17:31 weis Assigned To => weis
2007-11-09 17:31 weis Status new => confirmed
2008-09-10 17:05 doligez Relationship added related to 0003992
2008-09-10 17:35 doligez Note Added: 0004605
2008-09-10 17:35 doligez Status confirmed => closed
2008-09-10 17:35 doligez Resolution open => fixed
2008-09-10 17:35 doligez Fixed in Version => 3.11+dev
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker