Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004321OCamlOCaml generalpublic2007-06-20 19:532008-09-10 17:35
Reportertill 
Assigned Toweis 
PrioritynormalSeveritycrashReproducibilityalways
StatusclosedResolutionfixed 
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...

consider:

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
(0004094)
Christophe Troestler (reporter)
2007-06-21 19:21

Related to bug 0003992
(0004251)
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.
(0004605)
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


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker