Comments (4)
Thanks. You can fork the repo, add the patch, and push it back. Or, if it's a github issue, just attach the patch again in a few minues.
from freeradius-client.
Since it's short I'll just add it here:
--- lib/sendserver.c.orig 2018-01-23 10:57:07.861253190 +0100
+++ lib/sendserver.c 2018-01-23 11:19:12.328861458 +0100
@@ -214,6 +214,15 @@
*
*/
+/* Used to avoid casts between char buffers and the header struct since
+** this might cause alignment problems on some architectures.
+ */
+typedef union auth_buf_u
+{
+ AUTH_HDR hdr;
+ char buf[BUFFER_LEN];
+} auth_buf_t;
+
int rc_send_server (rc_handle *rh, SEND_DATA *data, char *msg)
{
int sockfd;
@@ -230,8 +239,8 @@
size_t secretlen;
char secret[MAX_SECRET_LENGTH + 1];
unsigned char vector[AUTH_VECTOR_LEN];
- char recv_buffer[BUFFER_LEN];
- char send_buffer[BUFFER_LEN];
+ auth_buf_t recv_auth_buf;
+ auth_buf_t send_auth_buf;
int retries;
VALUE_PAIR *vp;
struct pollfd pfd;
@@ -313,7 +322,7 @@
}
/* Build a request */
- auth = (AUTH_HDR *) send_buffer;
+ auth = &send_auth_buf.hdr;
auth->code = data->code;
auth->id = data->seq_nbr;
@@ -345,7 +354,7 @@
for (;;)
{
- sendto (sockfd, (char *) auth, (unsigned int) total_length, (int) 0,
+ sendto (sockfd, send_auth_buf.buf, (unsigned int) total_length, (int) 0,
SA(&sinremote), sizeof (struct sockaddr_in));
pfd.fd = sockfd;
@@ -383,8 +392,8 @@
}
}
salen = sizeof(sinremote);
- length = recvfrom (sockfd, (char *) recv_buffer,
- (int) sizeof (recv_buffer),
+ length = recvfrom (sockfd, recv_auth_buf.buf,
+ (int) sizeof (recv_auth_buf),
(int) 0, SA(&sinremote), &salen);
if (length <= 0)
@@ -396,7 +405,7 @@
return ERROR_RC;
}
- recv_auth = (AUTH_HDR *)recv_buffer;
+ recv_auth = &recv_auth_buf.hdr;
if (length < AUTH_HDR_LEN || length < ntohs(recv_auth->length)) {
rc_log(LOG_ERR, "rc_send_server: recvfrom: %s:%d: reply is too short",
from freeradius-client.
Someone pointed out that this is misusing unions. That's true, in theory, but in practice we know it will work. (The issue is that the standard doesn't guarantee that setting one union field and then reading the other will do what you expect.)
If you want to be very strict, I don't think you can guarantee that the AUTH_HDR struct layout will be compact either. (Although we know that it will, in sane implementations.)
Another solution is to simply change
char secret[MAX_SECRET_LENGTH + 1];
into
char secret[MAX_SECRET_LENGTH + 4];
but I thought that had a kludgy feel to it, and it still relies on casts.
Alternatively, don't use the AUTH_HDR overlay struct, and pack/unpack the header byte by byte instead.
from freeradius-client.
The simpler way to fix it is to just declare the buffer as uint64_t
instead of char
. The functions taking char *
will happily take a pointer cast from uint64_t *
. But the reverse isn't true.
from freeradius-client.
Related Issues (20)
- Encryption of CHAP-password HOT 2
- BUG: Dictionary attributes compared against UINT8_MAX HOT 3
- dictionary.sip cannot be used due to large attibute values HOT 5
- Is there a Java version for freeradius? HOT 1
- Does freeRadius support EAP_AKA? HOT 1
- I want use OTP two factor authentication HOT 2
- Does this library has plan to support windows ? HOT 1
- User-password and shared secret limits too low, should be 128. HOT 2
- configure.in contains a check that isn't C99 compliant as it's main function lacks a return type.
- Is there an openwrt package HOT 1
- Error in 1.1.8 when there is no entry for radius port in /etc/services HOT 1
- Bump up shared secret limit to 512? HOT 2
- Incorrect upper limit of 8k in config file HOT 1
- rc_avpair_tostr() crashes on bad PW_TYPE_DATE data HOT 1
- freeradius-clinet that supports PAM & PEAP/TLS-EAP HOT 1
- getaddrinfo memory leaks
- attribute issue with windows using dictionary.microsoft after successful connection in PPTP HOT 1
- Accounting only configuration HOT 3
- Freeradius Mssql DB HOT 1
- Facing Issue While Vendor Specific Configuration HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freeradius-client.