fix elyr buffer overflow, only escape if escape is necessary

This commit is contained in:
zmike 2014-02-06 12:11:59 -05:00
parent 0546ebb63d
commit a77401ce6f
1 changed files with 19 additions and 4 deletions

View File

@ -93,19 +93,34 @@ empc_module_metadata_fetch(const Empc_Fetch_Request *req)
eq->req = (Empc_Fetch_Request*)req;
eq->ereqs = eina_list_append(eq->ereqs, ereq);
s = song = calloc(1, strlen(req->song) * 3);
/* lyricwiki's api is fucking terrible and has no ability to do fuzzy matching
* because of this, it is frequently the case that song titles which include '-'
* will match wrong due to the lack of surrounding spaces.
* in this block, I'll attempt the shotgun approach and try fetching with sequential
* '-' escapes
*/
s = song = calloc(1, (strlen(req->song) * 3) + 1);
for (p = req->song; p[0]; p++, s++)
{
if (p[0] == '-')
Eina_Bool rep = EINA_FALSE;
if ((p - req->song > 0) && (p[0] == '-') && (p[-1] != ' ') && (p[-1] != '_'))
{
s[0] = '_';
s++;
rep = EINA_TRUE;
}
s[0] = p[0];
if (p[0] == '-')
{
s++;
s[0] = '_';
if ((p[1] != ' ') && (p[1] != '_'))
{
rep = EINA_TRUE;
s++;
s[0] = '_';
}
if (!rep) continue;
strcpy(s + 1, p + 1);
ereq = excetra_req_new(req->artist, song, (Excetra_Result_Cb)result_cb, eq);
if (ereq)