From: chrubis@suse.cz
To: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
Cc: vasily.isaenko@oracle.com, ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH 1/2] lib: tst_get_unused_uid, tst_get_unused_gid
Date: Mon, 13 Jan 2014 18:32:30 +0100 [thread overview]
Message-ID: <20140113173230.GC1945@rei> (raw)
In-Reply-To: <1389605723-17937-1-git-send-email-stanislav.kholmanskikh@oracle.com>
Hi!
> @@ -0,0 +1,86 @@
> +/*
> + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include <grp.h>
> +#include <limits.h>
> +#include <pwd.h>
> +#include <stdlib.h>
> +#include <sys/types.h>
> +#include <unistd.h>
> +
> +uid_t tst_get_unused_uid(void)
> +{
> + struct passwd pwd;
> + struct passwd *result;
> + char *buf;
> + size_t bufsize;
I've changed the bufsize to long, because size_t is unsigned.
Side note: I wonder why ltp has only -Wall and not -Wall -W which prints
warnings when signed and unsigned types are compared...
> + int s;
> + uid_t uid;
> +
> + bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
> + if (bufsize == -1)
> + bufsize = 16384;
> +
> + buf = malloc(bufsize);
> + if (buf == NULL)
> + return -1;
> +
> + for (uid = 0; uid <= UINT_MAX - 1; uid++) {
> + s = getpwuid_r(uid, &pwd, buf, bufsize, &result);
> + if (result == NULL) {
I've added a free(buf) here otherwise we will leak memory.
> + if (s == 0)
> + return uid;
> + else
> + return -1;
> + }
> + }
> +
> + free(buf);
> + return -1;
> +}
And the same for the second one.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2014-01-13 17:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <52CFC6D1.4060006@oracle.com>
2014-01-13 9:35 ` [LTP] [PATCH 1/2] lib: tst_get_unused_uid, tst_get_unused_gid Stanislav Kholmanskikh
2014-01-13 17:32 ` chrubis [this message]
2014-01-13 9:35 ` [LTP] [PATCH 2/2] setregid02, setresuid03: inval_user fix Stanislav Kholmanskikh
2014-01-13 17:38 ` chrubis
[not found] ` <52D4F37C.4050409@oracle.com>
2014-01-14 15:05 ` chrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140113173230.GC1945@rei \
--to=chrubis@suse.cz \
--cc=ltp-list@lists.sourceforge.net \
--cc=stanislav.kholmanskikh@oracle.com \
--cc=vasily.isaenko@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox