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

Skip to content

Commit c804c00

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 5674a25 commit c804c00

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
@@ -2355,14 +2355,16 @@ CheckCertAuth(Port *port)
23552355
*/
23562356

23572357
/*
2358-
* RADIUS authentication is described in RFC2865 (and several
2359-
* others).
2358+
* RADIUS authentication is described in RFC2865 (and several others).
23602359
*/
23612360

23622361
#define RADIUS_VECTOR_LENGTH 16
23632362
#define RADIUS_HEADER_LENGTH 20
23642363
#define RADIUS_MAX_PASSWORD_LENGTH 128
23652364

2365+
/* Maximum size of a RADIUS packet we will create or accept */
2366+
#define RADIUS_BUFFER_SIZE 1024
2367+
23662368
typedef struct
23672369
{
23682370
uint8 attribute;
@@ -2376,6 +2378,8 @@ typedef struct
23762378
uint8 id;
23772379
uint16 length;
23782380
uint8 vector[RADIUS_VECTOR_LENGTH];
2381+
/* this is a bit longer than strictly necessary: */
2382+
char pad[RADIUS_BUFFER_SIZE - RADIUS_VECTOR_LENGTH];
23792383
} radius_packet;
23802384

23812385
/* RADIUS packet types */
@@ -2392,9 +2396,6 @@ typedef struct
23922396
/* RADIUS service types */
23932397
#define RADIUS_AUTHENTICATE_ONLY 8
23942398

2395-
/* Maximum size of a RADIUS packet we will create or accept */
2396-
#define RADIUS_BUFFER_SIZE 1024
2397-
23982399
/* Seconds to wait - XXX: should be in a config variable! */
23992400
#define RADIUS_TIMEOUT 3
24002401

@@ -2429,10 +2430,12 @@ CheckRADIUSAuth(Port *port)
24292430
{
24302431
char *passwd;
24312432
char *identifier = "postgresql";
2432-
char radius_buffer[RADIUS_BUFFER_SIZE];
2433-
char receive_buffer[RADIUS_BUFFER_SIZE];
2434-
radius_packet *packet = (radius_packet *) radius_buffer;
2435-
radius_packet *receivepacket = (radius_packet *) receive_buffer;
2433+
radius_packet radius_send_pack;
2434+
radius_packet radius_recv_pack;
2435+
radius_packet *packet = &radius_send_pack;
2436+
radius_packet *receivepacket = &radius_recv_pack;
2437+
char *radius_buffer = (char *) &radius_send_pack;
2438+
char *receive_buffer = (char *) &radius_recv_pack;
24362439
int32 service = htonl(RADIUS_AUTHENTICATE_ONLY);
24372440
uint8 *cryptvector;
24382441
int encryptedpasswordlen;

0 commit comments

Comments
 (0)