On Fri 22-07-11 08:53:53, Nikiforov Alex wrote: > 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++) { > +
Why the empty line? > 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]); I would prefer it like this: if (!(*endptr)) goto bad_pid; snprintf(path, FILENAME_MAX, "/proc/%d", pid); if (stat(path, &buff_stat)) { bad_pid: fprintf(stderr, "Error: %s is not valid pid.\n", argv[i]); exit_code = 2; continue; } Why should we do snprintf if we know that the given parameter was not a number or it contains some garbage. -- Michal Hocko SUSE Labs SUSE LINUX s.r.o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic ------------------------------------------------------------------------------ 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