Skip to content

Commit

Permalink
Fix format string injection in safe errors (#20712)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Jan 16, 2025
1 parent 20090ab commit c031589
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compiler/src/dmd/safe.d
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ extern (D) void reportSafeError(FuncDeclaration fd, bool gag, Loc loc,
buf.writestring(" is not allowed in a `@safe` function");
else
buf.writestring(" is not allowed in a function with default safety with `-preview=safer`");
.error(loc, buf.extractChars());
.error(loc, "%s", buf.extractChars());
}
}
}
Expand Down Expand Up @@ -471,7 +471,7 @@ bool setUnsafe(Scope* sc,
OutBuffer buf;
buf.printf(format, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
buf.printf(" can't initialize `@safe` variable `%s`", sc.varDecl.toChars());
.error(loc, buf.extractChars());
.error(loc, "%s", buf.extractChars());

return true;
}
Expand All @@ -494,7 +494,7 @@ bool setUnsafe(Scope* sc,
OutBuffer buf;
buf.printf(format, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
buf.writestring(" is not allowed in a `@safe` function");
.error(loc, buf.extractChars());
.error(loc, "%s", buf.extractChars());
return true;
}
return false;
Expand Down Expand Up @@ -555,7 +555,7 @@ bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)
OutBuffer buf;
buf.printf(format, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
buf.writestring(" will become `@system` in a future release");
deprecation(loc, buf.extractChars());
deprecation(loc, "%s", buf.extractChars());
}
}
else if (!sc.func.safetyViolation)
Expand Down

0 comments on commit c031589

Please sign in to comment.