efl selection manager + elm dnd test fix with bad string handling

so there are 2 problems behind T7113. first is a problem in the efl
selection manager being "sloppy" with selection data. it's doing a
strlen on the data but it's not a normal c string. it's a blob of
binary data + length value. this fixes that "sloppiness" by using the
len field.

there is also another bug in the dnd test code that again has to do
with "sloppy" handling of data buffers and assuming nul byte
termination and not using the len field properly.

this fixes T7113.
This commit is contained in:
Carsten Haitzler 2018-07-16 16:31:53 +09:00
parent 6fa8c581b5
commit 5e58e58d60
3 changed files with 14 additions and 5 deletions

View File

@ -204,11 +204,15 @@ _grid_item_getcb(Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *xposret, int
static inline char *
_strndup(const char *str, size_t len)
{
size_t slen = strlen(str);
const char *p;
char *ret;
size_t slen;
if (slen > len) slen = len;
ret = malloc (slen + 1);
for (slen = 0, p = str;
(slen < len) && (*p);
p++, slen++);
ret = malloc(slen + 1);
if (!ret) return NULL;
if (slen > 0) memcpy(ret, str, slen);

View File

@ -1133,11 +1133,16 @@ static Eina_Bool
_x11_vcard_send(char *target EINA_UNUSED, void *data EINA_UNUSED, int size EINA_UNUSED, void **data_ret, int *size_ret, Ecore_X_Atom *ttype EINA_UNUSED, int *typesize EINA_UNUSED)
{
Sel_Manager_Selection *sel;
char *s;
sel_debug("Vcard send called");
sel = *(Sel_Manager_Selection **)data;
if (data_ret) *data_ret = strdup(sel->data.mem);
if (size_ret) *size_ret = strlen(sel->data.mem);
s = malloc(sel->data.len + 1);
if (!s) return EINA_FALSE;
memcpy(s, sel->data.mem, sel->data.len);
s[sel->data.len] = 0;
if (data_ret) *data_ret = s;
if (size_ret) *size_ret = sel->data.len;
return EINA_TRUE;
}