Skip to content

Unsoundness from premature drop of temporary in match scrutinee #10683

Closed
@kmcallister

Description

@kmcallister

We have some code in Servo of the form:

match name.to_ascii_lower().as_slice() {
    "margin-top"   =>  // stuff
    "margin-right" =>  // stuff
    // dozens more of these
}

The match will sometimes (nondeterministically) fail even though name matches one of the listed string literals. The bug apparently disappears if I change the code to

let name_lower = name.to_ascii_lower();
match name_lower.as_slice() {

So I believe the ~str returned by to_ascii_lower() is getting freed before the match is done. (I couldn't reproduce the bug inside Valgrind, however.)

You can see the actual Servo code here. It's a Mako template which outputs Rust code. If you build Servo you can see the generated code at src/components/style/properties.rs.

We're using

rustc 0.9-pre (67d7be0 2013-10-29 12:02:59 -0700)

so if you believe this bug is already fixed in master, let us know and we can upgrade.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions