[libselinux/f18] Clean up the setfcontext_compile atomic patch
Daniel J Walsh
dwalsh at fedoraproject.org
Fri Mar 8 17:42:17 UTC 2013
commit e469575cac9649aec66c89f9587e3e04b6618db7
Author: Dan Walsh <dwalsh at redhat.com>
Date: Fri Mar 8 12:42:08 2013 -0500
Clean up the setfcontext_compile atomic patch
- Make sure label_file code always sets errno
libselinux-f19.patch | 97 +++++++++++++++++++++++++++++++++-----------------
libselinux.spec | 6 +++-
2 files changed, 69 insertions(+), 34 deletions(-)
---
diff --git a/libselinux-f19.patch b/libselinux-f19.patch
index 7628143..eb44666 100644
--- a/libselinux-f19.patch
+++ b/libselinux-f19.patch
@@ -42,7 +42,7 @@ diff -up libselinux-2.1.12/src/getfilecon.c.f19 libselinux-2.1.12/src/getfilecon
if (ret < 0)
diff -up libselinux-2.1.12/src/label_file.c.f19 libselinux-2.1.12/src/label_file.c
--- libselinux-2.1.12/src/label_file.c.f19 2013-03-06 13:55:15.394795448 -0500
-+++ libselinux-2.1.12/src/label_file.c 2013-03-06 13:55:15.413795527 -0500
++++ libselinux-2.1.12/src/label_file.c 2013-03-08 12:37:41.305333387 -0500
@@ -245,6 +245,7 @@ static int load_mmap(struct selabel_hand
char *addr;
size_t len;
@@ -191,6 +191,23 @@ diff -up libselinux-2.1.12/src/label_file.c.f19 libselinux-2.1.12/src/label_file
free(data);
}
+@@ -624,6 +649,8 @@ static struct selabel_lookup_rec *lookup
+ break;
+ } else if (rc == PCRE_ERROR_NOMATCH)
+ continue;
++
++ errno = ENOENT;
+ /* else it's an error */
+ goto finish;
+ }
+@@ -635,6 +662,7 @@ static struct selabel_lookup_rec *lookup
+ goto finish;
+ }
+
++ errno = 0;
+ ret = &spec_arr[i].lr;
+
+ finish:
diff -up libselinux-2.1.12/src/label_file.h.f19 libselinux-2.1.12/src/label_file.h
--- libselinux-2.1.12/src/label_file.h.f19 2013-03-06 13:55:15.395795452 -0500
+++ libselinux-2.1.12/src/label_file.h 2013-03-06 13:55:15.414795531 -0500
@@ -242,24 +259,28 @@ diff -up libselinux-2.1.12/src/mapping.c.f19 libselinux-2.1.12/src/mapping.c
k++;
diff -up libselinux-2.1.12/utils/sefcontext_compile.c.f19 libselinux-2.1.12/utils/sefcontext_compile.c
--- libselinux-2.1.12/utils/sefcontext_compile.c.f19 2013-03-06 13:59:26.567841949 -0500
-+++ libselinux-2.1.12/utils/sefcontext_compile.c 2013-03-06 13:59:42.161906692 -0500
-@@ -6,6 +6,7 @@
- #include <string.h>
-
- #include <linux/limits.h>
-+#include <libgen.h>
-
- #include "../src/label_file.h"
-
-@@ -153,6 +154,7 @@ static int write_binary_file(struct save
++++ libselinux-2.1.12/utils/sefcontext_compile.c 2013-03-08 12:24:54.014002976 -0500
+@@ -145,7 +145,7 @@ static int process_file(struct saved_dat
+ * u32 - data length of the pcre regex study daya
+ * char - a buffer holding the raw pcre regex study data
+ */
+-static int write_binary_file(struct saved_data *data, char *filename)
++static int write_binary_file(struct saved_data *data, int fd)
+ {
+ struct spec *specs = data->spec_arr;
+ FILE *bin_file;
+@@ -153,8 +153,9 @@ static int write_binary_file(struct save
uint32_t magic = SELINUX_MAGIC_COMPILED_FCONTEXT;
uint32_t section_len;
uint32_t i;
+ int rc;
- bin_file = fopen(filename, "w");
+- bin_file = fopen(filename, "w");
++ bin_file = fdopen(fd, "w");
if (!bin_file) {
-@@ -163,19 +165,19 @@ static int write_binary_file(struct save
+ perror("fopen output_file");
+ exit(EXIT_FAILURE);
+@@ -163,19 +164,19 @@ static int write_binary_file(struct save
/* write some magic number */
len = fwrite(&magic, sizeof(uint32_t), 1, bin_file);
if (len != 1)
@@ -282,7 +303,7 @@ diff -up libselinux-2.1.12/utils/sefcontext_compile.c.f19 libselinux-2.1.12/util
for (i = 0; i < section_len; i++) {
char *stem = data->stem_arr[i].buf;
-@@ -184,20 +186,20 @@ static int write_binary_file(struct save
+@@ -184,20 +185,20 @@ static int write_binary_file(struct save
/* write the strlen (aka no nul) */
len = fwrite(&stem_len, sizeof(uint32_t), 1, bin_file);
if (len != 1)
@@ -306,7 +327,7 @@ diff -up libselinux-2.1.12/utils/sefcontext_compile.c.f19 libselinux-2.1.12/util
for (i = 0; i < section_len; i++) {
char *context = specs[i].lr.ctx_raw;
-@@ -208,82 +210,85 @@ static int write_binary_file(struct save
+@@ -208,82 +209,85 @@ static int write_binary_file(struct save
pcre_extra *sd = get_pcre_extra(&specs[i]);
uint32_t to_write;
size_t size;
@@ -408,38 +429,48 @@ diff -up libselinux-2.1.12/utils/sefcontext_compile.c.f19 libselinux-2.1.12/util
}
static int free_specs(struct saved_data *data)
-@@ -317,7 +322,8 @@ int main(int argc, char *argv[])
+@@ -317,7 +321,9 @@ int main(int argc, char *argv[])
const char *path;
char stack_path[PATH_MAX + 1];
int rc;
-
-+ char *tmp, *tmppath;
++ char *tmp= NULL;
++ int fd;
+
if (argc != 2) {
fprintf(stderr, "usage: %s input_file\n", argv[0]);
exit(EXIT_FAILURE);
-@@ -338,10 +344,21 @@ int main(int argc, char *argv[])
+@@ -338,13 +344,29 @@ int main(int argc, char *argv[])
rc = snprintf(stack_path, sizeof(stack_path), "%s.bin", path);
if (rc < 0 || rc >= sizeof(stack_path))
return rc;
- rc = write_binary_file(&data, stack_path);
-- if (rc < 0)
++
++ if (asprintf(&tmp, "%sXXXXXX", stack_path) < 0)
++ return -1;
++
++ fd = mkstemp(tmp);
++ if (fd < 0)
++ goto err;
++
++ rc = write_binary_file(&data, fd);
++
+ if (rc < 0)
- return rc;
++ goto err;
-+ tmppath = strdup(stack_path);
-+ if (!tmppath)
-+ return -1;
-+ tmp = tempnam(dirname(tmppath), ".bin");
-+ free(tmppath);
-+ if (!tmp)
-+ return -1;
-+ rc = write_binary_file(&data, tmp);
-+ if (rc < 0) {
-+ free(tmp);
-+ return rc;
-+ }
+ rename(tmp, stack_path);
-+ free(tmp);
rc = free_specs(&data);
if (rc < 0)
- return rc;
+- return rc;
++ goto err;
+
+- return 0;
++ rc = 0;
++out:
++ free(tmp);
++ return rc;
++err:
++ rc = -1;
++ goto out;
+ }
diff --git a/libselinux.spec b/libselinux.spec
index 227f641..32005db 100644
--- a/libselinux.spec
+++ b/libselinux.spec
@@ -10,7 +10,7 @@
Summary: SELinux library and simple utilities
Name: libselinux
Version: 2.1.12
-Release: 7.2%{?dist}
+Release: 7.3%{?dist}
License: Public Domain
Group: System Environment/Libraries
Source: %{name}-%{version}.tgz
@@ -243,6 +243,10 @@ rm -rf %{buildroot}
%{ruby_sitearch}/selinux.so
%changelog
+* Wed Mar 6 2013 Dan Walsh <dwalsh at redhat.com> - 2.1.12-7.3
+- Clean up the setfcontext_compile atomic patch
+- Make sure label_file code always sets errno
+
* Wed Mar 6 2013 Dan Walsh <dwalsh at redhat.com> - 2.1.12-7.2
- Make setfcontext_compile atomic
More information about the scm-commits
mailing list