[Mplayer-cvslog] CVS: main/libmpdemux/realrtsp real.c, 1.5, 1.6 rtsp.c, 1.7, 1.8
Roberto Togni CVS
syncmail at mplayerhq.hu
Sun Apr 25 02:17:26 CEST 2004
CVS change done by Roberto Togni CVS
Update of /cvsroot/mplayer/main/libmpdemux/realrtsp
In directory mail:/var2/tmp/cvs-serv10240
Modified Files:
real.c rtsp.c
Log Message:
More bounds checking fixes (thnaks to Miguel Freitas)
Index: real.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/realrtsp/real.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- real.c 24 Apr 2004 10:33:19 -0000 1.5
+++ real.c 25 Apr 2004 00:17:23 -0000 1.6
@@ -661,7 +661,7 @@
size-=12;
n=rtsp_read_data(rtsp_session, (*buffer)+12, size);
- return n+12;
+ return (n <= 0) ? 0 : n+12;
}
int convert_timestamp(char *str, int *sec, int *msec) {
@@ -744,7 +744,10 @@
description=malloc(sizeof(char)*(size+1));
- rtsp_read_data(rtsp_session, description, size);
+ if( rtsp_read_data(rtsp_session, description, size) <= 0) {
+ buf = xbuffer_free(buf);
+ return NULL;
+ }
description[size]=0;
/* parse sdp (sdpplin) and create a header and a subscribe string */
Index: rtsp.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/realrtsp/rtsp.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- rtsp.c 19 Dec 2003 22:49:29 -0000 1.7
+++ rtsp.c 25 Apr 2004 00:17:23 -0000 1.8
@@ -73,8 +73,6 @@
unsigned int server_state;
uint32_t server_caps;
- char buffer[BUF_SIZE]; /* scratch buffer */
-
unsigned int cseq;
char *session;
@@ -271,11 +269,12 @@
static char *rtsp_get(rtsp_t *s) {
int n=0;
- char *string;
+ char *buffer = malloc(BUF_SIZE);
+ char *string = NULL;
while (n<BUF_SIZE) {
- read_stream(s->s, &s->buffer[n], 1);
- if ((s->buffer[n-1]==0x0d)&&(s->buffer[n]==0x0a)) break;
+ read_stream(s->s, &(buffer[n]), 1);
+ if ((buffer[n-1]==0x0d)&&(buffer[n]==0x0a)) break;
n++;
}
@@ -284,7 +283,7 @@
exit(1);
}
string=malloc(sizeof(char)*n);
- memcpy(string,s->buffer,n-1);
+ memcpy(string,buffer,n-1);
string[n-1]=0;
#ifdef LOG
@@ -292,6 +291,7 @@
#endif
+ free(buffer);
return string;
}
@@ -352,8 +352,13 @@
static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) {
char **payload=s->scheduled;
- sprintf(s->buffer,"%s %s %s",type, what, rtsp_protocol_version);
- rtsp_put(s,s->buffer);
+ char *buf;
+
+ buf = malloc(strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3);
+
+ sprintf(buf,"%s %s %s",type, what, rtsp_protocol_version);
+ rtsp_put(s,buf);
+ free(buf);
if (payload)
while (*payload) {
rtsp_put(s,*payload);
@@ -369,11 +374,17 @@
static void rtsp_schedule_standard(rtsp_t *s) {
- sprintf(s->buffer, "Cseq: %u", s->cseq);
- rtsp_schedule_field(s, s->buffer);
+ char tmp[16];
+
+ snprintf(tmp, 16, "Cseq: %u", s->cseq);
+ rtsp_schedule_field(s, tmp);
+
if (s->session) {
- sprintf(s->buffer, "Session: %s", s->session);
- rtsp_schedule_field(s, s->buffer);
+ char *buf;
+ buf = malloc(strlen(s->session)+15);
+ sprintf(buf, "Session: %s", s->session);
+ rtsp_schedule_field(s, buf);
+ free(buf);
}
}
/*
@@ -388,6 +399,8 @@
int code;
answer=rtsp_get(s);
+ if (!answer)
+ return 0;
code=rtsp_get_code(answer);
free(answer);
@@ -396,6 +409,8 @@
do { /* while we get answer lines */
answer=rtsp_get(s);
+ if (!answer)
+ return 0;
if (!strncmp(answer,"Cseq:",5)) {
sscanf(answer,"Cseq: %u",&answer_seq);
@@ -407,26 +422,29 @@
}
}
if (!strncmp(answer,"Server:",7)) {
- sscanf(answer,"Server: %s",s->buffer);
+ char *buf = malloc(strlen(answer));
+ sscanf(answer,"Server: %s",buf);
if (s->server) free(s->server);
- s->server=strdup(s->buffer);
+ s->server=strdup(buf);
+ free(buf);
}
if (!strncmp(answer,"Session:",8)) {
- memset(s->buffer,0, BUF_SIZE);
- sscanf(answer,"Session: %s",s->buffer);
+ char *buf = calloc(1, strlen(answer));
+ sscanf(answer,"Session: %s",buf);
if (s->session) {
- if (strcmp(s->buffer, s->session)) {
- printf("rtsp: warning: setting NEW session: %s\n", s->buffer);
+ if (strcmp(buf, s->session)) {
+ printf("rtsp: warning: setting NEW session: %s\n", buf);
free(s->session);
- s->session=strdup(s->buffer);
+ s->session=strdup(buf);
}
} else
{
#ifdef LOG
- printf("rtsp: setting session id to: %s\n", s->buffer);
+ printf("rtsp: setting session id to: %s\n", s->buf);
#endif
- s->session=strdup(s->buffer);
+ s->session=strdup(buf);
}
+ free(buf);
}
*answer_ptr=answer;
answer_ptr++;
@@ -555,13 +573,15 @@
if ((buffer[0]=='S')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]=='_'))
{
char *rest=rtsp_get(s);
- /* a real server wanna play table tennis? */
- memcpy(s->buffer, buffer, 4);
- strcpy(s->buffer+4, rest);
+ if (!rest)
+ return -1;
+
seq=-1;
do {
free(rest);
rest=rtsp_get(s);
+ if (!rest)
+ return -1;
if (!strncmp(rest,"Cseq:",5))
sscanf(rest,"Cseq: %u",&seq);
} while (strlen(rest)!=0);
More information about the MPlayer-cvslog
mailing list