* Add strstrc() function which helps avoid a couple reads of unitialized memory.

This commit is contained in:
Justin Maggard 2009-11-12 01:53:40 +00:00
parent d25f3a6c14
commit 24ff2a8a1c
3 changed files with 44 additions and 9 deletions

View File

@ -254,12 +254,12 @@ intervening space) by either an integer or the keyword "infinite". */
h->reqflags |= FLAG_NO_RESIZE; h->reqflags |= FLAG_NO_RESIZE;
//h->reqflags |= FLAG_MIME_AVI_DIVX; //h->reqflags |= FLAG_MIME_AVI_DIVX;
} }
else if(strstr(p, "bridgeCo-DMP/3")) else if(strstrc(p, "bridgeCo-DMP/3", '\r'))
{ {
h->req_client = EDenonReceiver; h->req_client = EDenonReceiver;
h->reqflags |= FLAG_DLNA; h->reqflags |= FLAG_DLNA;
} }
else if(strstr(p, "fbxupnpav/")) else if(strstrc(p, "fbxupnpav/", '\r'))
{ {
h->req_client = EFreeBox; h->req_client = EFreeBox;
} }
@ -268,7 +268,7 @@ intervening space) by either an integer or the keyword "infinite". */
h->req_client = EPopcornHour; h->req_client = EPopcornHour;
h->reqflags |= FLAG_MIME_FLAC_FLAC; h->reqflags |= FLAG_MIME_FLAC_FLAC;
} }
else if(strcasestr(p, "DLNADOC/1.50")) else if(strstrc(p, "DLNADOC/1.50", '\r'))
{ {
h->req_client = EStandardDLNA150; h->req_client = EStandardDLNA150;
h->reqflags |= FLAG_DLNA; h->reqflags |= FLAG_DLNA;
@ -354,7 +354,9 @@ next_header:
h->req_chunklen = -1; h->req_chunklen = -1;
if( h->req_buflen <= h->req_contentoff ) if( h->req_buflen <= h->req_contentoff )
return; return;
while( (h->req_chunklen = strtol(line, &endptr, 16)) && (endptr != line) ) while( (line < (h->req_buf + h->req_buflen)) &&
(h->req_chunklen = strtol(line, &endptr, 16)) &&
(endptr != line) )
{ {
while(!(endptr[0] == '\r' && endptr[1] == '\n')) while(!(endptr[0] == '\r' && endptr[1] == '\n'))
{ {
@ -445,7 +447,7 @@ Send406(struct upnphttp * h)
{ {
static const char body406[] = static const char body406[] =
"<HTML><HEAD><TITLE>406 Not Acceptable</TITLE></HEAD>" "<HTML><HEAD><TITLE>406 Not Acceptable</TITLE></HEAD>"
"<BODY><H1>Not Acceptable</H1>An unsupported operation " "<BODY><H1>Not Acceptable</H1>An unsupported operation"
" was requested.</BODY></HTML>\r\n"; " was requested.</BODY></HTML>\r\n";
h->respflags = FLAG_HTML; h->respflags = FLAG_HTML;
BuildResp2_upnphttp(h, 406, "Not Acceptable", BuildResp2_upnphttp(h, 406, "Not Acceptable",
@ -721,6 +723,7 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h)
DPRINTF(E_WARN, L_HTTP, "DLNA %s requested, responding ERROR 406\n", DPRINTF(E_WARN, L_HTTP, "DLNA %s requested, responding ERROR 406\n",
h->reqflags&FLAG_TIMESEEK ? "TimeSeek" : "PlaySpeed"); h->reqflags&FLAG_TIMESEEK ? "TimeSeek" : "PlaySpeed");
Send406(h); Send406(h);
return;
} }
#endif #endif
else if(strcmp("GET", HttpCommand) == 0) else if(strcmp("GET", HttpCommand) == 0)
@ -765,7 +768,6 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h)
else if(strncmp(HttpUrl, "/Thumbnails/", 12) == 0) else if(strncmp(HttpUrl, "/Thumbnails/", 12) == 0)
{ {
SendResp_thumbnail(h, HttpUrl+12); SendResp_thumbnail(h, HttpUrl+12);
CloseSocket_upnphttp(h);
} }
else if(strncmp(HttpUrl, "/AlbumArt/", 10) == 0) else if(strncmp(HttpUrl, "/AlbumArt/", 10) == 0)
{ {
@ -1041,7 +1043,7 @@ send_data(struct upnphttp * h, char * header, size_t size)
n = send(h->socket, header, size, 0); n = send(h->socket, header, size, 0);
if(n<0) if(n<0)
{ {
DPRINTF(E_ERROR, L_HTTP, "send(res_buf): %s", strerror(errno)); DPRINTF(E_ERROR, L_HTTP, "send(res_buf): %s\n", strerror(errno));
} }
else if(n < h->res_buflen) else if(n < h->res_buflen)
{ {
@ -1196,7 +1198,8 @@ SendResp_albumArt(struct upnphttp * h, char * object)
"Connection: close\r\n" "Connection: close\r\n"
"Date: %s\r\n" "Date: %s\r\n"
"EXT:\r\n" "EXT:\r\n"
"contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_TN\r\n" "realTimeInfo.dlna.org: DLNA.ORG_TLAG=*\r\n"
"contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_TN\r\n"
"Server: " MINIDLNA_SERVER_STRING "\r\n", "Server: " MINIDLNA_SERVER_STRING "\r\n",
size, date); size, date);
@ -1334,6 +1337,7 @@ SendResp_thumbnail(struct upnphttp * h, char * object)
"Connection: close\r\n" "Connection: close\r\n"
"Date: %s\r\n" "Date: %s\r\n"
"EXT:\r\n" "EXT:\r\n"
"realTimeInfo.dlna.org: DLNA.ORG_TLAG=*\r\n"
"contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_TN\r\n" "contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_TN\r\n"
"Server: " MINIDLNA_SERVER_STRING "\r\n", "Server: " MINIDLNA_SERVER_STRING "\r\n",
ed->size, date); ed->size, date);
@ -1353,6 +1357,7 @@ SendResp_thumbnail(struct upnphttp * h, char * object)
} }
exif_data_unref(ed); exif_data_unref(ed);
} }
CloseSocket_upnphttp(h);
error: error:
sqlite3_free_table(result); sqlite3_free_table(result);
} }
@ -1472,6 +1477,7 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
"Connection: close\r\n" "Connection: close\r\n"
"Date: %s\r\n" "Date: %s\r\n"
"EXT:\r\n" "EXT:\r\n"
"realTimeInfo.dlna.org: DLNA.ORG_TLAG=*\r\n"
"contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_%s;DLNA.ORG_CI=1\r\n" "contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_%s;DLNA.ORG_CI=1\r\n"
"Server: " MINIDLNA_SERVER_STRING "\r\n", "Server: " MINIDLNA_SERVER_STRING "\r\n",
date, dlna_pn); date, dlna_pn);
@ -1555,9 +1561,10 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
} }
} }
DPRINTF(E_INFO, L_HTTP, "Done serving %s\n", file_path); DPRINTF(E_INFO, L_HTTP, "Done serving %s\n", file_path);
if( imsrc )
image_free(imsrc);
if( imdst ) if( imdst )
image_free(imdst); image_free(imdst);
image_free(imsrc);
resized_error: resized_error:
sqlite3_free_table(result); sqlite3_free_table(result);
#if USE_FORK #if USE_FORK
@ -1762,6 +1769,7 @@ SendResp_dlnafile(struct upnphttp * h, char * object)
"Connection: close\r\n" "Connection: close\r\n"
"Date: %s\r\n" "Date: %s\r\n"
"EXT:\r\n" "EXT:\r\n"
"realTimeInfo.dlna.org: DLNA.ORG_TLAG=*\r\n"
"contentFeatures.dlna.org: %s\r\n" "contentFeatures.dlna.org: %s\r\n"
"Server: " MINIDLNA_SERVER_STRING "\r\n\r\n", "Server: " MINIDLNA_SERVER_STRING "\r\n\r\n",
date, last_file.dlna); date, last_file.dlna);

24
utils.c
View File

@ -57,6 +57,30 @@ trim(char *str)
return str; return str;
} }
/* Find the first occurrence of p in s, where s is terminated by t */
char *
strstrc(const char *s, const char *p, const char t)
{
char *endptr;
size_t slen, plen;
endptr = strchr(s, t);
if (!endptr)
return NULL;
plen = strlen(p);
slen = endptr - s;
while (slen >= plen)
{
if (*s == *p && strncmp(s+1, p+1, plen-1) == 0)
return (char*)s;
s++;
slen--;
}
return NULL;
}
char * char *
modifyString(char * string, const char * before, const char * after, short like) modifyString(char * string, const char * before, const char * after, short like)
{ {

View File

@ -16,6 +16,9 @@ ends_with(const char * haystack, const char * needle);
char * char *
trim(char *str); trim(char *str);
char *
strstrc(const char *s, const char *p, const char t);
char * char *
modifyString(char * string, const char * before, const char * after, short like); modifyString(char * string, const char * before, const char * after, short like);