Avoid an odd undefined behavior with memcmp (src/bin/pg_rewind/pg_rewind.c)

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Avoid an odd undefined behavior with memcmp (src/bin/pg_rewind/pg_rewind.c)
Date: 2024-05-28 19:02:37
Message-ID: CAEudQAoT7GWNd1v2qgAT4f7chiwvx-GGJXxdHzODXjYkbQYQuw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi.

The function *perform_rewind* has an odd undefined behavior.
The function memcmp/ <https://cplusplus.com/reference/cstring/memcmp/>,
compares bytes to bytes.

IMO, I think that pg_rewind can have a security issue,
if two files are exactly the same, they are considered different.
Because use of structs with padding values is unspecified.

Fix by explicitly initializing with memset to avoid this.

best regards,
Ranier Vilela

Attachment Content-Type Size
avoid-undefined-compares-two-structs-with-padding-bytes-pg_rewind.patch application/octet-stream 1.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2024-05-28 19:13:17 Windows: openssl & gssapi dislike each other
Previous Message Imran Zaheer 2024-05-28 15:50:21 Re: errors building on windows using meson