---
name: "audit_encode_nv_string"
section: "3"
platform: "linux"
package: "audit"
version: "4.2.1-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/audit_encode_nv_string"
---

# audit\_encode\_nv\_string(3)

encode a name/value pair in a string

## NAME

audit\_encode\_nv\_string - encode a name/value pair in a string

## SYNOPSIS

```
#include <libaudit.h>
```

**char \*audit\_encode\_nv\_string(const char \****name***, const char \****value***, unsigned int** *vlen***)"**

## DESCRIPTION

This function formats a name/value pair for logging by the audit system. This should be used on any field being logged that might contain a space, a double-quote, a C0 control byte, a DEL byte, or a non-ASCII byte. Values containing those bytes have to be specially encoded for the auparse library to correctly handle the value. The encoding method is designed to prevent log injection attacks where malicious values could cause parsing errors.

To use this function, pass the *name* string and *value* string in their respective arguments. The *name* argument must not be NULL, and is copied as-is before the '=' separator. The value is checked with [**audit\_value\_needs\_encoding**(3)](/audit_value_needs_encoding/3.md). If encoding is needed, the returned string has the form *name*=*HEX*, where *HEX* is the uppercase hexadecimal encoding of the value bytes. If encoding is not needed, the returned string has the form *name*=*value*.

If *value* is NULL, a question mark is used as the value. If *vlen* is 0, the function uses [**strlen**(3)](/strlen/3.md) to determine the value length. If the value may contain an embedded NUL byte, pass the value length in *vlen* bytes.

Also be aware that the *name* of the field will cause auparse to do certain things when interpreting the value. If the *name* is uid, a user id value in decimal is expected. Make sure that well known names are used for their intended purpose or that there is no chance of name collision with something new.

## RETURN VALUE

Returns a freshly malloc'ed string that the caller must free or NULL on error.

## SEE ALSO

[**audit\_log\_user\_message**(3)](/audit_log_user_message/3.md), [**audit\_log\_user\_comm\_message**(3)](/audit_log_user_comm_message/3.md), [**audit\_log\_user\_avc\_message**(3)](/audit_log_user_avc_message/3.md), [**audit\_log\_semanage\_message**(3)](/audit_log_semanage_message/3.md), [**audit\_encode\_value**(3)](/audit_encode_value/3.md), [**audit\_value\_needs\_encoding**(3)](/audit_value_needs_encoding/3.md).

## AUTHOR

Steve Grubb
