Skip to content

Commit 4c051c4

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 7cbd944 commit 4c051c4

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
@@ -2570,14 +2570,16 @@ CheckCertAuth(Port *port)
25702570
*/
25712571

25722572
/*
2573-
* RADIUS authentication is described in RFC2865 (and several
2574-
* others).
2573+
* RADIUS authentication is described in RFC2865 (and several others).
25752574
*/
25762575

25772576
#define RADIUS_VECTOR_LENGTH 16
25782577
#define RADIUS_HEADER_LENGTH 20
25792578
#define RADIUS_MAX_PASSWORD_LENGTH 128
25802579

2580+
/* Maximum size of a RADIUS packet we will create or accept */
2581+
#define RADIUS_BUFFER_SIZE 1024
2582+
25812583
typedef struct
25822584
{
25832585
uint8 attribute;
@@ -2591,6 +2593,8 @@ typedef struct
25912593
uint8 id;
25922594
uint16 length;
25932595
uint8 vector[RADIUS_VECTOR_LENGTH];
2596+
/* this is a bit longer than strictly necessary: */
2597+
char pad[RADIUS_BUFFER_SIZE - RADIUS_VECTOR_LENGTH];
25942598
} radius_packet;
25952599

25962600
/* RADIUS packet types */
@@ -2607,9 +2611,6 @@ typedef struct
26072611
/* RADIUS service types */
26082612
#define RADIUS_AUTHENTICATE_ONLY 8
26092613

2610-
/* Maximum size of a RADIUS packet we will create or accept */
2611-
#define RADIUS_BUFFER_SIZE 1024
2612-
26132614
/* Seconds to wait - XXX: should be in a config variable! */
26142615
#define RADIUS_TIMEOUT 3
26152616

@@ -2734,10 +2735,12 @@ CheckRADIUSAuth(Port *port)
27342735
static int
27352736
PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identifier, char *user_name, char *passwd)
27362737
{
2737-
char radius_buffer[RADIUS_BUFFER_SIZE];
2738-
char receive_buffer[RADIUS_BUFFER_SIZE];
2739-
radius_packet *packet = (radius_packet *) radius_buffer;
2740-
radius_packet *receivepacket = (radius_packet *) receive_buffer;
2738+
radius_packet radius_send_pack;
2739+
radius_packet radius_recv_pack;
2740+
radius_packet *packet = &radius_send_pack;
2741+
radius_packet *receivepacket = &radius_recv_pack;
2742+
char *radius_buffer = (char *) &radius_send_pack;
2743+
char *receive_buffer = (char *) &radius_recv_pack;
27412744
int32 service = htonl(RADIUS_AUTHENTICATE_ONLY);
27422745
uint8 *cryptvector;
27432746
int encryptedpasswordlen;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy