Skip to content

slice: fix stpcpy off-by-one for header value extraction - #13181

Merged
traeak merged 2 commits into
apache:masterfrom
traeak:slice_hdr_val
Jun 9, 2026
Merged

slice: fix stpcpy off-by-one for header value extraction#13181
traeak merged 2 commits into
apache:masterfrom
traeak:slice_hdr_val

Conversation

@traeak

@traeak traeak commented May 20, 2026

Copy link
Copy Markdown
Contributor

The off by one wastes a single character, it doesn't overrun.

The off by one wastes a single character, it doesn't overrun.
@traeak
traeak requested a review from ezelkow1 May 20, 2026 13:01
@traeak traeak self-assigned this May 20, 2026
@bryancall
bryancall requested a review from Copilot June 1, 2026 22:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the slice plugin’s HttpHeader::valueForKey() helper to fix an off-by-one capacity check when copying a MIME header value into a caller-provided buffer, and clarifies the function’s contract in the header.

Changes:

  • Fixes the copy/termination capacity check to allow using the full available buffer (while still reserving space for '\0').
  • Adds input validation for nullptr output parameters and rejects invalid index values (< -1).
  • Updates the API comment to describe null-termination and caller responsibilities.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
plugins/slice/HttpHeader.h Clarifies valueForKey() output / null-termination expectations and buffer capacity responsibility.
plugins/slice/HttpHeader.cc Fixes the off-by-one condition in valueForKey() and adds some argument validation / initialization behavior.

Comment thread plugins/slice/HttpHeader.cc Outdated
@zwoop

zwoop commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

[approve ci]

Copilot AI review requested due to automatic review settings June 8, 2026 20:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@JosiahWI JosiahWI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This simplifies the logic flow.

@JosiahWI JosiahWI added the slice label Jun 9, 2026
@traeak
traeak merged commit b71ea74 into apache:master Jun 9, 2026
15 checks passed
@zwoop zwoop added this to the 11.0.0 milestone Jul 20, 2026
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jul 29, 2026
* slice: fix stpcpy off-by-one for header value extraction

The off by one wastes a single character, it doesn't overrun.

* HttpHeader: check for pass in zero length value

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jul 29, 2026
* slice: fix stpcpy off-by-one for header value extraction

The off by one wastes a single character, it doesn't overrun.

* HttpHeader: check for pass in zero length value

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
(cherry picked from commit b71ea74)
@github-project-automation github-project-automation Bot moved this from Picked v10.2.0 to For v10.2.0 in ATS v10.2.x Jul 29, 2026
@cmcfarlen cmcfarlen moved this to Picked v10.2.0 in ATS v10.2.x Jul 29, 2026
@cmcfarlen cmcfarlen modified the milestones: 11.0.0, 10.2.0 Jul 29, 2026
@cmcfarlen cmcfarlen moved this from For v10.2.0 to Picked v10.2.0 in ATS v10.2.x Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Picked v10.2.0

Development

Successfully merging this pull request may close these issues.

5 participants