libsepol/cil: bail out on snprintf failure
PATCH 1/1 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]>
--- libsepol/cil/src/cil.c | 6 ++++++ 1 file changed, 6 insertions(+)
libsepol/cil/src/cil.c +6 -0
@@ -1456,6 +1456,12 @@ int cil_userprefixes_to_string(struct cil_db *db, char **out, size_t *size) buf_pos =snprintf (str_tmp, str_len,"user %s prefix %s;\n" , user->datum.fqn, userprefix->prefix_str); +if (buf_pos <0 ) { +free (str_tmp); + *size =0 ; + *out =NULL ; + goto exit; + } str_len -= buf_pos; str_tmp += buf_pos; }
Signature · 1 line
2.34.1
Quoted 8 lines · Christian Göttsche
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]>
Acked-by James Carter <[email protected]>
Quoted 24 lines
--- libsepol/cil/src/cil.c | 6 ++++++ 1 file changed, 6 insertions(+)libsepol/cil/src/cil.c +6
-1@@ -1456,6 +1456,12 @@ int cil_userprefixes_to_string(struct cil_db *db, char **out, size_t *size) buf_pos =snprintf (str_tmp, str_len,"user %s prefix %s;\n" , user->datum.fqn, userprefix->prefix_str); +if (buf_pos <0 ) { +free (str_tmp); + *size =0 ; + *out =NULL ; + goto exit; + } str_len -= buf_pos; str_tmp += buf_pos; } --2.34.1
Quoted 8 lines · James Carter
Quoted 5 lines · Christian Göttsche
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.
Quoted 6 lines
Quoted 3 lines
Found by GitHub CodeQL.
Signed-off-by Christian Göttsche <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 24 lines
Quoted 24 lines
--- libsepol/cil/src/cil.c | 6 ++++++ 1 file changed, 6 insertions(+)libsepol/cil/src/cil.c +6
-1@@ -1456,6 +1456,12 @@ int cil_userprefixes_to_string(struct cil_db *db, char **out, size_t *size) buf_pos =snprintf (str_tmp, str_len,"user %s prefix %s;\n" , user->datum.fqn, userprefix->prefix_str); +if (buf_pos <0 ) { +free (str_tmp); + *size =0 ; + *out =NULL ; + goto exit; + } str_len -= buf_pos; str_tmp += buf_pos; } --2.34.1