1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 16:18:48 -05:00

Fix portability issue related with unaligned memory access

This commit is contained in:
Yang Tse 2010-02-03 06:49:27 +00:00
parent f6d288a397
commit 381a4d6efe
2 changed files with 22 additions and 10 deletions

View File

@ -54,6 +54,11 @@
*/ */
#define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1])))
#define RTP_PKT_LENGTH(p) ((((int)((unsigned char)((p)[2]))) << 8) | \
((int)((unsigned char)((p)[3]))))
static int rtsp_getsock_do(struct connectdata *conn, static int rtsp_getsock_do(struct connectdata *conn,
curl_socket_t *socks, curl_socket_t *socks,
int numsocks); int numsocks);
@ -544,16 +549,14 @@ CURLcode Curl_rtsp_rtp_readwrite(struct SessionHandle *data,
while((rtp_dataleft > 0) && while((rtp_dataleft > 0) &&
(rtp[0] == '$')) { (rtp[0] == '$')) {
if(rtp_dataleft > 4) { if(rtp_dataleft > 4) {
char channel;
int rtp_length; int rtp_length;
/* Parse the header */ /* Parse the header */
/* The channel identifier immediately follows and is 1 byte */ /* The channel identifier immediately follows and is 1 byte */
channel = rtp[1]; rtspc->rtp_channel = RTP_PKT_CHANNEL(rtp);
rtspc->rtp_channel = (int) channel;
/* The length is two bytes */ /* The length is two bytes */
rtp_length = ntohs( *((unsigned short *)(&rtp[2])) ); rtp_length = RTP_PKT_LENGTH(rtp);
if(rtp_dataleft < rtp_length + 4) { if(rtp_dataleft < rtp_length + 4) {
/* Need more - incomplete payload*/ /* Need more - incomplete payload*/

View File

@ -33,6 +33,11 @@
#include "memdebug.h" #include "memdebug.h"
#define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1])))
#define RTP_PKT_LENGTH(p) ((((int)((unsigned char)((p)[2]))) << 8) | \
((int)((unsigned char)((p)[3]))))
#define RTP_DATA_SIZE 12 #define RTP_DATA_SIZE 12
static const char *RTP_DATA = "$_1234\n\0asdf"; static const char *RTP_DATA = "$_1234\n\0asdf";
@ -40,16 +45,18 @@ static int rtp_packet_count = 0;
static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) { static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) {
char *data = (char *)ptr; char *data = (char *)ptr;
int channel = (int)data[1]; int channel = RTP_PKT_CHANNEL(data);
int message_size = (int)(size * nmemb - 4); int message_size = (int)(size * nmemb) - 4;
unsigned short coded_size = ntohs(*((unsigned short*)(&data[2]))); int coded_size = RTP_PKT_LENGTH(data);
size_t failure = (size * nmemb) ? 0 : 1;
int i; int i;
(void)stream; (void)stream;
printf("RTP: message size %d, channel %d\n", message_size, channel); printf("RTP: message size %d, channel %d\n", message_size, channel);
if((unsigned short) message_size != coded_size) { if(message_size != coded_size) {
printf("RTP embedded size (%hu) does not match the write size (%d).\n", printf("RTP embedded size (%d) does not match the write size (%d).\n",
coded_size, message_size); coded_size, message_size);
return failure;
} }
data += 4; data += 4;
@ -57,11 +64,13 @@ static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) {
if(message_size - i > RTP_DATA_SIZE) { if(message_size - i > RTP_DATA_SIZE) {
if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE) != 0) { if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE) != 0) {
printf("RTP PAYLOAD CORRUPTED [%s]\n", data + i); printf("RTP PAYLOAD CORRUPTED [%s]\n", data + i);
return failure;
} }
} else { } else {
if (memcmp(RTP_DATA, data + i, message_size - i) != 0) { if (memcmp(RTP_DATA, data + i, message_size - i) != 0) {
printf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n", printf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n",
message_size - i, data + i); message_size - i, data + i);
return failure;
} }
} }
} }