libappamor: Fix mode string NUL-termination of aa_getcon() functions

r2125 caused a regression in aa_getpeercon_raw() when a NULL pointer was
passed into the mode parameter. Instead of unconditionally
NUL-terminating the con string before the mode portion of the security
context, it made it to where the NUL byte was only put into place when
mode was non-NULL.

This resulted in the con string incorrectly containing the label and the
mode.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
Tyler Hicks 2013-09-04 14:50:55 -07:00
parent 05029cb9b7
commit 54382a9bf5

View file

@ -194,6 +194,7 @@ int aa_getprocattr_raw(pid_t tid, const char *attr, char *buf, int len,
int rc = -1;
int fd, ret;
char *tmp = NULL;
char *mode_str;
int size = 0;
if (!buf || len <= 0) {
@ -246,8 +247,9 @@ int aa_getprocattr_raw(pid_t tid, const char *attr, char *buf, int len,
size++;
}
mode_str = parse_confinement_mode(buf, size);
if (mode)
*mode = parse_confinement_mode(buf, size);
*mode = mode_str;
}
rc = size;