libselinux: avoid regex serialization truncations

Check (for the probably impossible) case the serialized data is longer
than the compiled fcontext format supports.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Christian Göttsche 2023-08-09 19:55:17 +02:00 committed by James Carter
parent f1a8afc272
commit 4eea9948d3

View File

@ -176,7 +176,7 @@ int regex_writef(struct regex_data *regex, FILE *fp, int do_write_precompregex)
/* encode the pattern for serialization */
rc = pcre2_serialize_encode((const pcre2_code **)&regex->regex,
1, &bytes, &serialized_size, NULL);
if (rc != 1) {
if (rc != 1 || serialized_size >= UINT32_MAX) {
rc = -1;
goto out;
}