ps: address a potential 'newline' quirk the libselinux

Sometimes with libselinux present but SELinux inactive
the context reported is "unconfined" which contains an
embedded newline. This then causes misalignment of any
subsequent data. So, ps will now protect against that.

Reference(s):
http://www.freelists.org/post/procps/enablelibselinux-switch,14

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2013-08-07 12:58:57 -05:00 committed by Jaromir Capik
parent 46a1356219
commit 7c4894dd22

View File

@ -1339,6 +1339,7 @@ static int pr_context(char *restrict const outbuf, const proc_t *restrict const
len = strlen(context); len = strlen(context);
if(len > max_len) len = max_len; if(len > max_len) len = max_len;
memcpy(outbuf, context, len); memcpy(outbuf, context, len);
if (outbuf[len-1] == '\n') --len;
outbuf[len] = '\0'; outbuf[len] = '\0';
free(context); free(context);
}else{ }else{