Page MenuHomePhabricator

[bug] Check work of eina_binbuf_insert_length()
Closed, ResolvedPublic

Description

Please check work of API with wrong input parameter:
(code above have successfully work and return "buffer" as string, but with length = 11)

cstr = (unsigned char*)malloc(sizeof(unsigned char) * 7);
cstr[0] = 'b';
cstr[1] = 'u';
cstr[2] = 'f';
cstr[3] = 'f';
cstr[4] = 'e';
cstr[5] = 'r';
cstr[6] = '\0';

buf = eina_binbuf_manage_new_length(cstr, 7);
if (buf == NULL)
  {
     free(cstr);
     return;
  }
if (!eina_binbuf_insert_length(buf, "buf", 4, 1000))
  {
     eina_binbuf_string_free(buf);
     eina_binbuf_free(buf);
     return;
  }
if (11 != eina_binbuf_length_get(buf) || (strcmp(eina_binbuf_string_get(buf), "buffer")))
  {
     eina_binbuf_string_free(buf);
     eina_binbuf_free(buf);
     return;
  }
se.osadchy added subscribers: artem.popov, rimmed, NikaWhite.
jpeg added a subscriber: jpeg.Nov 15 2017, 2:29 AM

I think this is "undefined behaviour" as the API explicitely requires pos < length.

se.osadchy closed this task as Resolved.Dec 11 2017, 6:14 AM