Skip to content

server: anchor dsml_attr attribute match to a name boundary - #757

Open
Flor1an-B wants to merge 1 commit into
antirez:mainfrom
Flor1an-B:dsml-attr-anchor-attribute-match
Open

server: anchor dsml_attr attribute match to a name boundary#757
Flor1an-B wants to merge 1 commit into
antirez:mainfrom
Flor1an-B:dsml-attr-anchor-attribute-match

Conversation

@Flor1an-B

Copy link
Copy Markdown

Bug

dsml_attr() locates an attribute with an unanchored strstr(tag, "name=\"").
An earlier attribute whose name ends in the sought name followed by =" shadows
the real one:

  • <|DSML|invoke fullname="wrong" name="right">dsml_attr(tag, "name") returns "wrong".
  • <|DSML|invoke fullname="x">dsml_attr(tag, "name") returns "x" for a name that is absent.

The generated-DSML tool-call parser (parse_deepseek_generated_message_ex) feeds
whole invoke/parameter tags through this helper, so a drifted model tag
carrying an extra attribute could yield the wrong tool name or argument value.

Low severity: the server's own renderer emits fixed single attributes in a fixed
order, so round-tripping its output is unaffected — the bug needs a model tag
that puts a colliding attribute before name/string. It is still a real
correctness defect in the helper.

Fix

Match only at an attribute boundary (start of tag, or after whitespace), and
guard the snprintf pattern against truncation.

Test

--server gains test_dsml_attr_anchors_attribute_name. It fails on the old
helper
(returns "wrong" / "x", two assertions) and passes after the fix.
Built -Wall -Wextra, 0 warnings, Apple M5 Max.

🤖 Generated with Claude Code

dsml_attr() located an attribute with an unanchored strstr(tag, "name=\""),
so an earlier attribute whose name ends in the sought name followed by ="
shadowed the real one: on `<...invoke fullname="wrong" name="right">`,
dsml_attr(tag, "name") returned "wrong", and on `<...invoke fullname="x">`
it returned "x" for a "name" that is absent. The generated-DSML tool-call
parser feeds whole invoke/parameter tags through this helper, so a drifted
model tag with an extra attribute could yield the wrong tool name or
argument value. (The server's own renderer emits fixed single attributes in
a fixed order, so round-tripping its output is unaffected.)

Match only at an attribute boundary (start of tag, or after whitespace),
and guard the snprintf pattern against truncation.

Test: --server (test_dsml_attr_anchors_attribute_name); it fails on the old
helper (returns "wrong"/"x") and passes after the fix. Built -Wall -Wextra,
0 warnings, on Apple M5 Max.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.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.

1 participant