Page MenuHomeFreeBSD

db/hash_page.c: Reswap memory buffer in __put_page when dealing with a different byte order
AbandonedPublic

Authored by bnovkov on Aug 28 2025, 11:17 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Sep 29, 8:52 AM
Unknown Object (File)
Wed, Sep 24, 4:40 PM
Unknown Object (File)
Mon, Sep 22, 11:54 PM
Unknown Object (File)
Sep 15 2025, 4:19 AM
Unknown Object (File)
Aug 30 2025, 8:39 AM
Unknown Object (File)
Aug 29 2025, 7:34 PM
Unknown Object (File)
Aug 29 2025, 7:34 PM
Subscribers

Details

Reviewers
None
Group Reviewers
Klara
Summary

__put_page appropriately swaps the contents of its in-memory buffers
when operating on a database that was created on a machine with a
different byte order. However, it does not revert the buffer to its
original state, leading to a corrupted buffer and possible
database corruption.

Address this by "unswapping" the buffer before returning from the function.

Sponsored by: Klara, Inc.
Inspired by: https://github.com/apple-oss-distributions/Libc

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 66592
Build 63475: arc lint + arc unit

Event Timeline

markj added inline comments.
lib/libc/db/hash/hash_page.c
584

Here we're copying the caller-supplied buffer onto the stack and byte-swapping that, so I don't think there's any purpose in restoring the original order?

bnovkov marked an inline comment as done.
bnovkov added inline comments.
lib/libc/db/hash/hash_page.c
584

oh, I hadn't noticed that memcpy, thanks!

In that case yes, there's no need to restore the order.
I'll go ahead and abandon the revision.