Skip to content

include/buffer.h: make the unsigned constructors of ptr and list expl… - #72838

Open
MaxKellermann wants to merge 4 commits into
ceph:mainfrom
MaxKellermann:buffer__explicit_unsigned_ctors
Open

MaxKellermann wants to merge 4 commits into
ceph:mainfrom
MaxKellermann:buffer__explicit_unsigned_ctors

Conversation

@MaxKellermann

Copy link
Copy Markdown
Member

…icit

Constructing a buffer::ptr or a buffer::list from an unsigned (allocation length / preallocation size) was allowed implicitly, which means any integer could silently be converted to an empty buffer, e.g. when passed to a function taking a buffer::ptr or buffer::list parameter.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@MaxKellermann
MaxKellermann force-pushed the buffer__explicit_unsigned_ctors branch from ca3c2c7 to 58f7e5f Compare October 19, 2026 12:49
@MaxKellermann

Copy link
Copy Markdown
Member Author

This change found bug #72837 and thus needs to include its fix in order to be buildable.

Signed-off-by: Max Kellermann <[email protected]>
…ound_encode()

The parameter was `const ceph::buffer::ptr&` instead of
`const health_status_t&`.  This only compiled because the enum was
implicitly converted to `unsigned` and then to a buffer::ptr via its
implicit `ptr(unsigned)` constructor, allocating a temporary buffer
of 0..2 bytes on every bound_encode() call.

Signed-off-by: Max Kellermann <[email protected]>
…trs()

setxattrs() encoded the attribute map into `bl`, but then passed
`bl.length()` instead of `bl` to add_xattr(), which was implicitly
converted to an empty buffer::list via its `list(unsigned prealloc)`
constructor, so the attributes were never sent.

This regression was caused 17 years ago by commit 7a624a4 ("osd:
hold op data on the specific op") which removed the "valuelen"
overload of add_xattr().  Nobody ever noticed that bug because this is
dead code.

Signed-off-by: Max Kellermann <[email protected]>
…icit

Constructing a buffer::ptr or a buffer::list from an `unsigned`
(allocation length / preallocation size) was allowed implicitly,
which means any integer could silently be converted to an empty
buffer, e.g. when passed to a function taking a buffer::ptr or
buffer::list parameter.

Signed-off-by: Max Kellermann <[email protected]>
@MaxKellermann
MaxKellermann force-pushed the buffer__explicit_unsigned_ctors branch from 58f7e5f to af76467 Compare October 19, 2026 14:40
@MaxKellermann
MaxKellermann requested a review from a team as a code owner October 19, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant