mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 03:50:31 +00:00
Ensure that when encoding the contents of an ast_frame into an iax_frame, that
the size of the destination buffer is known in the iax_frame so that code won't write past the end of the allocated buffer when sending outgoing frames. (ASA-2007-014) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@75444 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -4020,7 +4020,9 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
|
||||
int sendmini=0;
|
||||
unsigned int lastsent;
|
||||
unsigned int fts;
|
||||
|
||||
|
||||
frb.fr2.afdatalen = sizeof(frb.buffer);
|
||||
|
||||
if (!pvt) {
|
||||
ast_log(LOG_WARNING, "No private structure for packet?\n");
|
||||
return -1;
|
||||
@@ -6435,7 +6437,8 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
|
||||
/* allocate an iax_frame with 4096 bytes of data buffer */
|
||||
fr = alloca(sizeof(*fr) + 4096);
|
||||
fr->callno = 0;
|
||||
|
||||
fr->afdatalen = 4096; /* From alloca() above */
|
||||
|
||||
res = recvfrom(fd, buf, sizeof(buf), 0,(struct sockaddr *) &sin, &len);
|
||||
if (res < 0) {
|
||||
if (errno != ECONNREFUSED)
|
||||
|
@@ -904,13 +904,20 @@ void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f)
|
||||
fr->af.delivery.tv_usec = 0;
|
||||
fr->af.data = fr->afdata;
|
||||
if (fr->af.datalen) {
|
||||
size_t copy_len = fr->af.datalen;
|
||||
if (copy_len > fr->afdatalen) {
|
||||
ast_log(LOG_ERROR, "Losing frame data because destination buffer size '%d' bytes not big enough for '%d' bytes in the frame\n",
|
||||
(int) fr->afdatalen, (int) fr->af.datalen);
|
||||
copy_len = fr->afdatalen;
|
||||
}
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
/* We need to byte-swap slinear samples from network byte order */
|
||||
if ((fr->af.frametype == AST_FRAME_VOICE) && (fr->af.subclass == AST_FORMAT_SLINEAR)) {
|
||||
ast_swapcopy_samples(fr->af.data, f->data, fr->af.samples);
|
||||
/* 2 bytes / sample for SLINEAR */
|
||||
ast_swapcopy_samples(fr->af.data, f->data, copy_len / 2);
|
||||
} else
|
||||
#endif
|
||||
memcpy(fr->af.data, f->data, fr->af.datalen);
|
||||
memcpy(fr->af.data, f->data, copy_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -919,6 +926,7 @@ struct iax_frame *iax_frame_new(int direction, int datalen)
|
||||
struct iax_frame *fr;
|
||||
fr = malloc((int)sizeof(struct iax_frame) + datalen);
|
||||
if (fr) {
|
||||
fr->afdatalen = datalen;
|
||||
fr->direction = direction;
|
||||
fr->retrans = -1;
|
||||
frames++;
|
||||
|
@@ -119,6 +119,8 @@ struct iax_frame {
|
||||
struct iax_frame *prev;
|
||||
/* Actual, isolated frame header */
|
||||
struct ast_frame af;
|
||||
/* Amount of data _allocated_ for afdata */
|
||||
size_t afdatalen;
|
||||
unsigned char unused[AST_FRIENDLY_OFFSET];
|
||||
unsigned char afdata[0]; /* Data for frame */
|
||||
};
|
||||
|
Reference in New Issue
Block a user