When compile_regex() calls regex_prepare_data() and this function fails in the following condition: *regex = regex_data_create(); if (!(*regex)) return -1; ... error_data has been zero-ed and compile_regex() calls: regex_format_error(&error_data, regex_error_format_buffer, sizeof(regex_error_format_buffer)); This leads to a call to strlen(error_data->error_buffer), where error_data->error_buffer is NULL. Avoid this by checking that error_data->error_buffer is not NULL before calling strlen(). This issue has been found using clang's static analyzer: https://337-118970575-gh.circle-artifacts.com/0/output-scan-build/2019-09-01-181851-6152-1/report-0b122b.html#EndPath Signed-off-by: Nicolas Iooss <nicolas.iooss@xxxxxxx> --- libselinux/src/regex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libselinux/src/regex.c b/libselinux/src/regex.c index a6fcbbfec1f3..f967efe4a32f 100644 --- a/libselinux/src/regex.c +++ b/libselinux/src/regex.c @@ -546,7 +546,7 @@ void regex_format_error(struct regex_error_data const *error_data, char *buffer, if (rc < 0) abort(); - if ((size_t)rc < strlen(error_data->error_buffer)) + if (error_data->error_buffer && (size_t)rc < strlen(error_data->error_buffer)) goto truncated; #endif -- 2.22.0