From f1390d329b1172bfc38b43bb11a56b8cb6db1af8 Mon Sep 17 00:00:00 2001
From: Alex Nikiforov <nika@gentoo>
Date: Thu, 21 Jul 2011 13:20:48 +0400
Subject: [PATCH 1/2] cgclassify: add a PID check into the client

Add PID check code to the client. We dont need any read()/write() if
it's not valid.

Signed-off-by: Alex Nikiforov <a.nikifo...@samsung.com>
---
  src/tools/cgclassify.c |    9 +++++++--
  1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c
index 397b725..cffc63f 100644
--- a/src/tools/cgclassify.c
+++ b/src/tools/cgclassify.c
@@ -121,7 +121,8 @@ int main(int argc, char *argv[])
        struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
        int c;
        char *endptr;
-
+       char path[FILENAME_MAX];
+       struct stat buff_stat;

        if (argc < 2) {
                usage(1, argv[0]);
@@ -167,8 +168,12 @@ int main(int argc, char *argv[])
        }

        for (i = optind; i < argc; i++) {
+
                pid = (uid_t) strtol(argv[i], &endptr, 10);
-               if (endptr[0] != '\0') {
+               snprintf(path, FILENAME_MAX, "/proc/%d", pid);
+
+               /* check PID */
+               if (endptr[0] != '\0' || stat(path, &buff_stat)) {
                        /* the input argument was not a number */
                        fprintf(stderr, "Error: %s is not valid pid.\n",
                                argv[i]);
-- 
1.7.4.1


------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to