libsepol/cil: Move initialization of bitmap in __cil_permx_to_bitmap()

Nicolas Iooss reports:
  When __cil_permx_to_bitmap() calls __cil_permx_str_to_int() on an
  invalid number, local variablt "bitmap" is left initialized when
  the function returns and its memory is leaked.

  This memory leak has been found by running clang's Address Sanitizer
  on a set of policies generated by American Fuzzy Lop.

Move the initialization of bitmap to right before ebitmap_set_bit()
and after the call to __cil_permx_str_to_int().

Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
This commit is contained in:
James Carter 2017-02-21 13:11:15 -05:00
parent 95e5c103f3
commit a2d40aaeba

View File

@ -797,13 +797,12 @@ static int __cil_permx_to_bitmap(struct cil_symtab_datum *datum, ebitmap_t *bitm
int rc = SEPOL_ERR;
uint16_t val;
ebitmap_init(bitmap);
rc = __cil_permx_str_to_int((char*)datum, &val);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_init(bitmap);
if (ebitmap_set_bit(bitmap, (unsigned int)val, 1)) {
cil_log(CIL_ERR, "Failed to set permissionx bit\n");
ebitmap_destroy(bitmap);