Make the memory layout of Port struct independent of USE_OPENSSL
authorHeikki Linnakangas <[email protected]>
Fri, 22 Nov 2024 15:43:04 +0000 (17:43 +0200)
committerHeikki Linnakangas <[email protected]>
Fri, 22 Nov 2024 15:43:34 +0000 (17:43 +0200)
Commit d39a49c1e4 added new fields to the struct, but missed the "keep
these last" comment on the previous fields. Add placeholder variables
so that the offsets of the fields are the same whether you build with
USE_OPENSSL or not. This is a courtesy to extensions that might peek
at the fields, to make the ABI the same regardless of the options used
to build PostgreSQL.

In reality, I don't expect any extensions to look at the 'raw_buf'
fields. Firstly, they are new in v17, so no one's written such
extensions yet. Secondly, extensions should have no business poking at
those fields anyway. Nevertheless, fix this properly on 'master'. On
v17, we mustn't change the memory layout, so just fix the comments.

Author: Jacob Champion
Discussion: https://www.postgresql.org/message-id/raw/CAOYmi%2BmKVJNzn5_TD_MK%[email protected]

src/include/libpq/libpq-be.h

index 05cb1874c580e022332bab298cf797a19c61debe..6a1a2274c5538897c20d44d05d425e79cfab22e2 100644 (file)
@@ -189,7 +189,8 @@ typedef struct Port
    /*
     * If GSSAPI is supported and used on this connection, store GSSAPI
     * information.  Even when GSSAPI is not compiled in, store a NULL pointer
-    * to keep struct offsets the same (for extension ABI compatibility).
+    * to keep struct offsets of the "SSL structures" below the same (for
+    * extension ABI compatibility).
     */
    pg_gssinfo *gss;
 #else
@@ -206,8 +207,7 @@ typedef struct Port
    bool        alpn_used;
 
    /*
-    * OpenSSL structures. (Keep these last so that the locations of other
-    * fields are the same whether or not you build with SSL enabled.)
+    * OpenSSL structures.
     */
 #ifdef USE_OPENSSL
    SSL        *ssl;
@@ -222,6 +222,9 @@ typedef struct Port
     * There's no API to "unread", the upper layer just places the data in the
     * Port structure in raw_buf and sets raw_buf_remaining to the amount of
     * bytes unread and raw_buf_consumed to 0.
+    *
+    * NB: the offsets of these fields depend on USE_OPENSSL.  These should
+    * not be accessed in an extension because of the ABI incompatibility.
     */
    char       *raw_buf;
    ssize_t     raw_buf_consumed,