diff mbox

[1/2] libselinux: procattr: return error on invalid pid_t input.

Message ID 1456259040-13721-2-git-send-email-dcashman@android.com (mailing list archive)
State Accepted
Headers show

Commit Message

Daniel Cashman Feb. 23, 2016, 8:23 p.m. UTC
From: dcashman <dcashman@android.com>

Signed-off-by: Daniel Cashman <dcashman@android.com>
---
 libselinux/src/procattr.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Stephen Smalley Feb. 24, 2016, 2:21 p.m. UTC | #1
On 02/23/2016 03:23 PM, Daniel Cashman wrote:
> From: dcashman <dcashman@android.com>
>
> Signed-off-by: Daniel Cashman <dcashman@android.com>

Thanks, applied.

> ---
>   libselinux/src/procattr.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/libselinux/src/procattr.c b/libselinux/src/procattr.c
> index 527a0a5..c20f003 100644
> --- a/libselinux/src/procattr.c
> +++ b/libselinux/src/procattr.c
> @@ -70,9 +70,9 @@ static int openattr(pid_t pid, const char *attr, int flags)
>   	char *path;
>   	pid_t tid;
>
> -	if (pid > 0)
> +	if (pid > 0) {
>   		rc = asprintf(&path, "/proc/%d/attr/%s", pid, attr);
> -	else {
> +	} else if (pid == 0) {
>   		rc = asprintf(&path, "/proc/thread-self/attr/%s", attr);
>   		if (rc < 0)
>   			return -1;
> @@ -82,6 +82,9 @@ static int openattr(pid_t pid, const char *attr, int flags)
>   		free(path);
>   		tid = gettid();
>   		rc = asprintf(&path, "/proc/self/task/%d/attr/%s", tid, attr);
> +	} else {
> +		errno = EINVAL;
> +		return -1;
>   	}
>   	if (rc < 0)
>   		return -1;
>
diff mbox

Patch

diff --git a/libselinux/src/procattr.c b/libselinux/src/procattr.c
index 527a0a5..c20f003 100644
--- a/libselinux/src/procattr.c
+++ b/libselinux/src/procattr.c
@@ -70,9 +70,9 @@  static int openattr(pid_t pid, const char *attr, int flags)
 	char *path;
 	pid_t tid;
 
-	if (pid > 0)
+	if (pid > 0) {
 		rc = asprintf(&path, "/proc/%d/attr/%s", pid, attr);
-	else {
+	} else if (pid == 0) {
 		rc = asprintf(&path, "/proc/thread-self/attr/%s", attr);
 		if (rc < 0)
 			return -1;
@@ -82,6 +82,9 @@  static int openattr(pid_t pid, const char *attr, int flags)
 		free(path);
 		tid = gettid();
 		rc = asprintf(&path, "/proc/self/task/%d/attr/%s", tid, attr);
+	} else {
+		errno = EINVAL;
+		return -1;
 	}
 	if (rc < 0)
 		return -1;