Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3455ddb

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 e0e1ef4 commit 3455ddb

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
@@ -2384,13 +2384,15 @@ CheckCertAuth(Port *port)
23842384
*/
23852385

23862386
/*
2387-
* RADIUS authentication is described in RFC2865 (and several
2388-
* others).
2387+
* RADIUS authentication is described in RFC2865 (and several others).
23892388
*/
23902389

23912390
#define RADIUS_VECTOR_LENGTH 16
23922391
#define RADIUS_HEADER_LENGTH 20
23932392

2393+
/* Maximum size of a RADIUS packet we will create or accept */
2394+
#define RADIUS_BUFFER_SIZE 1024
2395+
23942396
typedef struct
23952397
{
23962398
uint8 attribute;
@@ -2404,6 +2406,8 @@ typedef struct
24042406
uint8 id;
24052407
uint16 length;
24062408
uint8 vector[RADIUS_VECTOR_LENGTH];
2409+
/* this is a bit longer than strictly necessary: */
2410+
char pad[RADIUS_BUFFER_SIZE - RADIUS_VECTOR_LENGTH];
24072411
} radius_packet;
24082412

24092413
/* RADIUS packet types */
@@ -2420,9 +2424,6 @@ typedef struct
24202424
/* RADIUS service types */
24212425
#define RADIUS_AUTHENTICATE_ONLY 8
24222426

2423-
/* Maximum size of a RADIUS packet we will create or accept */
2424-
#define RADIUS_BUFFER_SIZE 1024
2425-
24262427
/* Seconds to wait - XXX: should be in a config variable! */
24272428
#define RADIUS_TIMEOUT 3
24282429

@@ -2458,10 +2459,12 @@ CheckRADIUSAuth(Port *port)
24582459
{
24592460
char *passwd;
24602461
char *identifier = "postgresql";
2461-
char radius_buffer[RADIUS_BUFFER_SIZE];
2462-
char receive_buffer[RADIUS_BUFFER_SIZE];
2463-
radius_packet *packet = (radius_packet *) radius_buffer;
2464-
radius_packet *receivepacket = (radius_packet *) receive_buffer;
2462+
radius_packet radius_send_pack;
2463+
radius_packet radius_recv_pack;
2464+
radius_packet *packet = &radius_send_pack;
2465+
radius_packet *receivepacket = &radius_recv_pack;
2466+
char *radius_buffer = (char *) &radius_send_pack;
2467+
char *receive_buffer = (char *) &radius_recv_pack;
24652468
int32 service = htonl(RADIUS_AUTHENTICATE_ONLY);
24662469
uint8 *cryptvector;
24672470
uint8 encryptedpassword[RADIUS_VECTOR_LENGTH];

0 commit comments

Comments
 (0)