src/driver/netfile.cpp fix skip over bufer size

This commit is contained in:
Jacek Jendrzej
2016-03-10 18:49:57 +01:00
parent dc9dff2f58
commit 30b1cdb459

View File

@@ -1708,16 +1708,13 @@ int f_status(FILE *stream, void (*cb)(void*))
/* information into the CSTATE structure */ /* information into the CSTATE structure */
void ShoutCAST_ParseMetaData(char *md, CSTATE *state) void ShoutCAST_ParseMetaData(char *md, CSTATE *state)
{ {
#define SKIP(a) for(;(a && !isalnum(*a)); ++a) {};
char *ptr;
/* abort if we were submitted a NULL pointer */ /* abort if we were submitted a NULL pointer */
if((!md) || (!state)) if((!md) || (!state))
return; return;
dprintf(stderr, "ShoutCAST_ParseMetaData(%p : %s, %p)\n", md, md, state); dprintf(stderr, "ShoutCAST_ParseMetaData(%p : %s, %p)\n", md, md, state);
ptr = strstr(md, "StreamTitle="); char *ptr = strstr(md, "StreamTitle=");
if(ptr) if(ptr)
{ {
@@ -1727,13 +1724,13 @@ void ShoutCAST_ParseMetaData(char *md, CSTATE *state)
if(!ptr) if(!ptr)
ptr = strstr(md, ", "); ptr = strstr(md, ", ");
const int bufsize = 4095;
/* no separator, simply copy everything into the 'title' field */ /* no separator, simply copy everything into the 'title' field */
if(!ptr) if(!ptr)
{ {
ptr = strchr(md, '='); ptr = strchr(md, '=');
strncpy(state->title, ptr + 2, 4095); strncpy(state->title, ptr + 2, bufsize);
state->title[4095] = '\0'; state->title[bufsize] = '\0';
ptr = strchr(state->title, ';'); ptr = strchr(state->title, ';');
if(ptr) if(ptr)
*(ptr - 1) = 0; *(ptr - 1) = 0;
@@ -1741,16 +1738,18 @@ void ShoutCAST_ParseMetaData(char *md, CSTATE *state)
} }
else else
{ {
SKIP(ptr); //SKIP()
strcpy(state->title, ptr); for(int i = 0;(ptr && i < bufsize && !isalnum(*ptr)); ++ptr,i++){};
strncpy(state->title, ptr,bufsize);
ptr = strchr(state->title, ';'); ptr = strchr(state->title, ';');
if(ptr) if(ptr)
*(ptr - 1) = 0; *(ptr - 1) = 0;
ptr = strstr(md, "StreamTitle="); ptr = strstr(md, "StreamTitle=");
ptr = strchr(ptr, '\''); ptr = strchr(ptr, '\'');
strncpy(state->artist, ptr + 1, 4095); strncpy(state->artist, ptr + 1, bufsize);
state->artist[4095] = '\0'; state->artist[bufsize] = '\0';
ptr = strstr(state->artist, " - "); ptr = strstr(state->artist, " - ");
if(!ptr) if(!ptr)
ptr = strstr(state->artist, ", "); ptr = strstr(state->artist, ", ");