From: Daniel J Walsh <dwalsh@redhat.com>
To: Stephen Smalley <sds@epoch.ncsc.mil>, SELinux <SELinux@tycho.nsa.gov>
Subject: libselinux patch to add file_context.homedirs and remove potential memory and fd leaks.
Date: Thu, 10 Feb 2005 16:53:42 -0500 [thread overview]
Message-ID: <420BD7E6.4000208@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: diff --]
[-- Type: text/plain, Size: 2402 bytes --]
diff --exclude-from=exclude -N -u -r nsalibselinux/src/matchpathcon.c libselinux-1.21.9/src/matchpathcon.c
--- nsalibselinux/src/matchpathcon.c 2005-01-31 13:50:18.000000000 -0500
+++ libselinux-1.21.9/src/matchpathcon.c 2005-02-10 16:51:59.000000000 -0500
@@ -519,10 +519,13 @@
{
FILE *fp;
FILE *localfp;
+ FILE *homedirfp;
char local_path[PATH_MAX + 1];
+ char homedir_path[PATH_MAX + 1];
char line_buf[BUFSIZ + 1];
unsigned int lineno, pass, i, j, maxnspec;
spec_t *spec_copy;
+ int status=-1;
/* Open the specification file. */
if (!path)
@@ -530,6 +533,9 @@
if ((fp = fopen(path, "r")) == NULL)
return -1;
+ snprintf(homedir_path, sizeof(homedir_path), "%s.homedirs", path);
+ homedirfp = fopen(homedir_path, "r");
+
snprintf(local_path, sizeof(local_path), "%s.local", path);
localfp = fopen(local_path, "r");
@@ -547,33 +553,41 @@
nspec = 0;
while (fgets_unlocked(line_buf, sizeof line_buf, fp) && nspec < maxnspec) {
if (process_line(path, line_buf, pass, ++lineno) != 0)
- return -1;
+ goto finish;
}
+ if (homedirfp)
+ while (fgets_unlocked(line_buf, sizeof line_buf, homedirfp) && nspec < maxnspec) {
+ if (process_line(homedir_path, line_buf, pass, ++lineno) != 0)
+ goto finish;
+ }
+
+
if (localfp)
while (fgets_unlocked(line_buf, sizeof line_buf, localfp) && nspec < maxnspec) {
if (process_line(local_path, line_buf, pass, ++lineno) != 0)
- return -1;
+ goto finish;
}
if (pass == 0) {
- if (nspec == 0)
- return 0;
+ if (nspec == 0) {
+ status = 0;
+ goto finish;
+ }
if ((spec_arr = malloc(sizeof(spec_t) * nspec)) ==
NULL)
- return -1;
+ goto finish;
memset(spec_arr, '\0', sizeof(spec_t) * nspec);
maxnspec = nspec;
rewind(fp);
+ if (homedirfp) rewind(homedirfp);
if (localfp) rewind(localfp);
}
}
- fclose(fp);
- if (localfp) fclose(localfp);
/* Move exact pathname specifications to the end. */
spec_copy = malloc(sizeof(spec_t) * nspec);
if (!spec_copy)
- return -1;
+ goto finish;
j = 0;
for (i = 0; i < nspec; i++) {
if (spec_arr[i].hasMetaChars)
@@ -588,7 +602,13 @@
nodups_specs(path);
- return 0;
+ status = 0;
+ finish:
+ fclose(fp);
+ if (spec_arr != spec_copy) free(spec_arr);
+ if (homedirfp) fclose(homedirfp);
+ if (localfp) fclose(localfp);
+ return status;
}
hidden_def(matchpathcon_init)
next reply other threads:[~2005-02-10 21:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-10 21:53 Daniel J Walsh [this message]
2005-02-17 16:06 ` libselinux patch to add file_context.homedirs and remove potential memory and fd leaks 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=420BD7E6.4000208@redhat.com \
--to=dwalsh@redhat.com \
--cc=SELinux@tycho.nsa.gov \
--cc=sds@epoch.ncsc.mil \
/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.