Skip to content

Commit b2ba721

Browse files
cgzonesjwcart2
authored andcommitted
libsepol/cil: bail out on snprintf failure
Do not continue with a negative return value once a string append operation fails to avoid increasing the buffer length variable `str_len`, potentially leading to an out-of-bounds write. Found by GitHub CodeQL. Signed-off-by: Christian Göttsche <[email protected]>
1 parent 5e6e516 commit b2ba721

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

libsepol/cil/src/cil.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,12 @@ int cil_userprefixes_to_string(struct cil_db *db, char **out, size_t *size)
14561456

14571457
buf_pos = snprintf(str_tmp, str_len, "user %s prefix %s;\n", user->datum.fqn,
14581458
userprefix->prefix_str);
1459+
if (buf_pos < 0) {
1460+
free(str_tmp);
1461+
*size = 0;
1462+
*out = NULL;
1463+
goto exit;
1464+
}
14591465
str_len -= buf_pos;
14601466
str_tmp += buf_pos;
14611467
}

0 commit comments

Comments
 (0)