audit: handle error from audit_encode_nv_string()

audit_encode_nv_string() is documented that it might fail. Handle
the error.

Also, the returned string was allocated with malloc(). We must free
that with free()/nm_auto_free, not g_free()/gs_free.
This commit is contained in:
Thomas Haller 2022-05-09 15:33:54 +02:00
parent 9ee37e42e1
commit d2f71b273e
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -135,10 +135,13 @@ build_message(NMStrBuf *strbuf, AuditBackend backend, GPtrArray *fields)
#if HAVE_LIBAUDIT
if (backend == BACKEND_AUDITD) {
if (field->need_encoding) {
gs_free char *value = NULL;
nm_auto_free char *value = NULL;
value = audit_encode_nv_string(field->name, str, 0);
nm_str_buf_append(strbuf, value);
if (value)
nm_str_buf_append(strbuf, value);
else
nm_str_buf_append_printf(strbuf, "%s=???", field->name);
} else
nm_str_buf_append_printf(strbuf, "%s=%s", field->name, str);
continue;