Skip to content

Commit

Permalink
libsepol: use logging framework in ebitmap.c
Browse files Browse the repository at this point in the history
Use the internal logging framework instead of directly writing to
stdout as it might be undesired to do so within a library.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones authored and jwcart2 committed Dec 15, 2021
1 parent 5c178f9 commit 852f14d
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions libsepol/src/ebitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ int ebitmap_read(ebitmap_t * e, void *fp)
count = le32_to_cpu(buf[2]);

if (mapsize != MAPSIZE) {
printf
("security: ebitmap: map size %d does not match my size %zu (high bit was %d)\n",
ERR(NULL, "security: ebitmap: map size %d does not match my size %zu (high bit was %d)\n",
mapsize, MAPSIZE, e->highbit);
goto bad;
}
Expand All @@ -416,8 +415,7 @@ int ebitmap_read(ebitmap_t * e, void *fp)
goto ok;
}
if (e->highbit & (MAPSIZE - 1)) {
printf
("security: ebitmap: high bit (%d) is not a multiple of the map size (%zu)\n",
ERR(NULL, "security: ebitmap: high bit (%d) is not a multiple of the map size (%zu)\n",
e->highbit, MAPSIZE);
goto bad;
}
Expand All @@ -429,12 +427,12 @@ int ebitmap_read(ebitmap_t * e, void *fp)
for (i = 0; i < count; i++) {
rc = next_entry(buf, fp, sizeof(uint32_t));
if (rc < 0) {
printf("security: ebitmap: truncated map\n");
ERR(NULL, "security: ebitmap: truncated map\n");
goto bad;
}
n = (ebitmap_node_t *) malloc(sizeof(ebitmap_node_t));
if (!n) {
printf("security: ebitmap: out of memory\n");
ERR(NULL, "security: ebitmap: out of memory\n");
rc = -ENOMEM;
goto bad;
}
Expand All @@ -443,34 +441,30 @@ int ebitmap_read(ebitmap_t * e, void *fp)
n->startbit = le32_to_cpu(buf[0]);

if (n->startbit & (MAPSIZE - 1)) {
printf
("security: ebitmap start bit (%d) is not a multiple of the map size (%zu)\n",
ERR(NULL, "security: ebitmap start bit (%d) is not a multiple of the map size (%zu)\n",
n->startbit, MAPSIZE);
goto bad_free;
}
if (n->startbit > (e->highbit - MAPSIZE)) {
printf
("security: ebitmap start bit (%d) is beyond the end of the bitmap (%zu)\n",
ERR(NULL, "security: ebitmap start bit (%d) is beyond the end of the bitmap (%zu)\n",
n->startbit, (e->highbit - MAPSIZE));
goto bad_free;
}
rc = next_entry(&map, fp, sizeof(uint64_t));
if (rc < 0) {
printf("security: ebitmap: truncated map\n");
ERR(NULL, "security: ebitmap: truncated map\n");
goto bad_free;
}
n->map = le64_to_cpu(map);

if (!n->map) {
printf
("security: ebitmap: null map in ebitmap (startbit %d)\n",
ERR(NULL, "security: ebitmap: null map in ebitmap (startbit %d)\n",
n->startbit);
goto bad_free;
}
if (l) {
if (n->startbit <= l->startbit) {
printf
("security: ebitmap: start bit %d comes after start bit %d\n",
ERR(NULL, "security: ebitmap: start bit %d comes after start bit %d\n",
n->startbit, l->startbit);
goto bad_free;
}
Expand All @@ -481,8 +475,7 @@ int ebitmap_read(ebitmap_t * e, void *fp)
l = n;
}
if (count && l->startbit + MAPSIZE != e->highbit) {
printf
("security: ebitmap: high bit %u has not the expected value %zu\n",
ERR(NULL, "security: ebitmap: high bit %u has not the expected value %zu\n",
e->highbit, l->startbit + MAPSIZE);
goto bad;
}
Expand Down

0 comments on commit 852f14d

Please sign in to comment.