From: Joshua Brindle <jbrindle@tresys.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: SELinux List <SELinux@tycho.nsa.gov>
Subject: Re: [PATCH] semanage - rename instead of copy
Date: Mon, 07 Nov 2005 16:50:17 -0500 [thread overview]
Message-ID: <436FCC19.6020700@tresys.com> (raw)
In-Reply-To: <1131399305.20591.151.camel@moss-spartans.epoch.ncsc.mil>
Stephen Smalley wrote:
> On Mon, 2005-11-07 at 16:25 -0500, Joshua Brindle wrote:
>
>>Attached patch makes libsemanage copy file to a temporary file and then
>>rename() instead of copying directly to the target. This is necessary so
>>that an install failure doesn't leave a corrupt binary policy on the
>>system.
>
>
> diff -purN -x .svn libsemanage/src/semanage_store.c libsemanage/src/semanage_store.c
> --- libsemanage/src/semanage_store.c 2005-11-07 11:52:28.000000000 -0500
> +++ libsemanage/src/semanage_store.c 2005-11-07 16:06:04.000000000 -0500
> @@ -305,12 +305,18 @@ static int semanage_filename_select(cons
> * overwrite it. Returns 0 on success, -1 on error. */
> static int semanage_copy_file(const char *src, const char *dst) {
> int in, out, retval = 0, amount_read;
> + char tmp[PATH_MAX] = {};
> char buf[4192];
>
> if ((in = open(src, O_RDONLY)) == -1) {
> return -1;
> }
> - if ((out = open(dst, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == -1) {
> +
> + snprintf(tmp, PATH_MAX, "%s.tmp", dst);
> + if (!tmp)
> + return -1;
> +
>
> If you want to check for failure on the snprintf, you need something like:
> int n = snprintf(tmp, PATH_MAX, "%s.tmp", dst);
> if (n < 0 || n >= PATH_MAX)
> return -1;
>
good point, also strlen(dst) can't be PATH_MAX or the filename will be
truncated and you'll end up with rename(dst,dst). Do you want a new
patch or are you going to fix this before commiting?
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
next prev parent reply other threads:[~2005-11-07 21:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-07 21:25 [PATCH] semanage - rename instead of copy Joshua Brindle
2005-11-07 21:35 ` Stephen Smalley
2005-11-07 21:50 ` Joshua Brindle [this message]
2005-11-08 13:34 ` Stephen Smalley
2005-11-08 14:05 ` Stephen Smalley
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=436FCC19.6020700@tresys.com \
--to=jbrindle@tresys.com \
--cc=SELinux@tycho.nsa.gov \
--cc=sds@tycho.nsa.gov \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.