Skip to content

fix: Repair bad string formatting - missing args, dangerous format spec - #2145

Merged
lgritz merged 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-badformat
Aug 16, 2026
Merged

fix: Repair bad string formatting - missing args, dangerous format spec#2145
lgritz merged 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-badformat

Conversation

@lgritz

@lgritz lgritz commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

RendererServices default implementations of errorfmt(), warningfmt(), etc, passed the formatted error string directly to Context::errorfmt() as the sole argument, like

context->errorfmt(some_string);

But even though it's a single plain string with no intentional arguments to format, what if that string happens to containing std::format-like formatting directives, like "{hello world}", that will confuse the heck out of the underlying string formatting engine? The correct code all along was:

context->errorfmt("{}", any_string_ok_here);

Also happened to find a use of fmt in typecheck.cpp where it didn't pass an argument implied by the format spec.

Additionally, for safety in a somewhat related way, make decode_message not crash, and print debug info, if the underlying format_to_n throws an exception.

RendererServices default implementations of errorfmt(), warningfmt(),
etc, passed the formatted error string directly to Context::errorfmt()
as the sole argument, like

    context->errorfmt(some_string);

But even though it's a single plain string with no intentional
arguments to format, what if that string happens to containing
std::format-like formatting directives, like "{hello world}", that
will confuse the heck out of the underlying string formatting engine?
The correct code all along was:

    context->errorfmt("{}", any_string_ok_here);

Also happened to find a use of fmt in typecheck.cpp where it didn't pass an
argument implied by the format spec.

Additionally, for safety in a somewhat related way, make
decode_message not crash, and print debug info, if the underlying
format_to_n throws an exception.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz
lgritz requested a review from grdanny August 15, 2026 07:43

@grdanny grdanny left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the quick fix!

@lgritz
lgritz merged commit 0848570 into AcademySoftwareFoundation:main Aug 16, 2026
26 checks passed
@lgritz
lgritz deleted the lg-badformat branch August 16, 2026 18:53
lgritz added a commit to lgritz/OpenShadingLanguage that referenced this pull request Aug 17, 2026
…ec (AcademySoftwareFoundation#2145)

RendererServices default implementations of errorfmt(), warningfmt(),
etc, passed the formatted error string directly to Context::errorfmt()
as the sole argument, like

    context->errorfmt(some_string);

But even though it's a single plain string with no intentional
arguments to format, what if that string happens to containing
std::format-like formatting directives, like "{hello world}", that
will confuse the heck out of the underlying string formatting engine?
The correct code all along was:

    context->errorfmt("{}", any_string_ok_here);

Also happened to find a use of fmt in typecheck.cpp where it didn't pass an
argument implied by the format spec.

Additionally, for safety in a somewhat related way, make
decode_message not crash, and print debug info, if the underlying
format_to_n throws an exception.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants