8000 Fix unportable disregard of alignment requirements in RADIUS code. · thatguystone/postgres@24fc43d · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 24fc43d

Browse files
committed
Fix unportable disregard of alignment requirements in RADIUS code.
The compiler is entitled to store a char[] local variable with no particular alignment requirement. Our RADIUS code cavalierly took such a local variable and cast its address to a struct type that does have alignment requirements. On an alignment-picky machine this would lead to bus errors. To fix, declare the local variable honestly, and then cast its address to char * for use in the I/O calls. Given the lack of field complaints, there must be very few if any people affected; but nonetheless this is a clear portability issue, so back-patch to all supported branches. Noted while looking at a Coverity complaint in the same code.
1 parent 42a60aa commit 24fc43d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/backend/libpq/auth.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,13 +2168,15 @@ CheckCertAuth(Port *port)
21682168
*/
21692169

21702170
/*
2171-
* RADIUS authentication is described in RFC2865 (and several
2172-
* others).
2171+
* RADIUS authentication is described in RFC2865 (and several others).
21732172
*/
21742173

21752174
#define RADIUS_VECTOR_LENGTH 16
21762175
#define RADIUS_HEADER_LENGTH 20
21772176

2177+
/* Maximum size of a RADIUS packet we will create or accept */
2178+
#define RADIUS_BUFFER_SIZE 1024
2179+
21782180
typedef struct
21792181
{
21802182
uint8 attribute;
@@ -2188,6 +2190,8 @@ typedef struct
21882190
uint8 id;
21892191
uint16 length;
21902192
uint8 vector[RADIUS_VECTOR_LENGTH];
2193+
/* this is a bit longer than strictly necessary: */
2194+
char pad[RADIUS_BUFFER_SIZE - RADIUS_VECTOR_LENGTH];
21912195
} radius_packet;
21922196

21932197
/* RADIUS packet types */
@@ -2204,9 +2208,6 @@ typedef struct
22042208
/* RADIUS service types */
22052209
#define RADIUS_AUTHENTICATE_ONLY 8
22062210

2207-
/* Maximum size of a RADIUS packet we will create or accept */
2208-
#define RADIUS_BUFFER_SIZE 1024
2209-
22102211
/* Seconds to wait - XXX: should be in a config variable! */
22112212
#define RADIUS_TIMEOUT 3
22122213

@@ -2241,10 +2242,12 @@ CheckRADIUSAuth(Port *port)
22412242
{
22422243
char *passwd;
22432244
char *identifier = "postgresql";
2244-
char radius_buffer[RADIUS_BUFFER_SIZE];
2245-
char receive_buffer[RADIUS_BUFFER_SIZE];
2246-
radius_packet *packet = (radius_packet *) radius_buffer;
2247-
radius_packet *receivepacket = (radius_packet *) receive_buffer;
2245+
radius_packet radius_send_pack;
2246+
radius_packet radius_recv_pack;
2247+
radius_packet *packet = &radius_send_pack;
2248+
radius_packet *receivepacket = &radius_recv_pack;
2249+
char *radius_buffer = (char *) &radius_send_pack;
2250+
char *receive_buffer = (char *) &radius_recv_pack;
22482251
int32 service = htonl(RADIUS_AUTHENTICATE_ONLY);
22492252
uint8 *cryptvector;
22502253
uint8 encryptedpassword[RADIUS_VECTOR_LENGTH];

0 commit comments

Comments
 (0)
0