|
From: <kma...@us...> - 2007-02-01 21:19:20
|
Revision: 2214
http://svn.sourceforge.net/selinux/?rev=2214&view=rev
Author: kmacmillan
Date: 2007-02-01 13:19:18 -0800 (Thu, 01 Feb 2007)
Log Message:
-----------
Author: "Todd C. Miller"
Email: Tod...@sp...
Subject: PATCH: libselinux matchpathcon() eliminate %as scanf format
Date: Thu, 25 Jan 2007 18:59:22 -0500 (EST)
This is a patch I sent in last year but forgot to split up as
requested; it still applies to the recently-released selinux-1.34.0.
THe patch replaces usage of the non-standard %as scanf() format
(which conflicts with C99) with strtok_r(). This does mean that
line_buf is modified but this variable is only used as an argument
to process_line() and is freed thereafter.
I made this change as part of the port of libselinux to SEBSD and
SEDarwin.
- todd
Acked-by: Karl MacMillan with minor style updates.
Modified Paths:
--------------
branches/stable/1_0/libselinux/ChangeLog
branches/stable/1_0/libselinux/src/matchpathcon.c
Modified: branches/stable/1_0/libselinux/ChangeLog
===================================================================
--- branches/stable/1_0/libselinux/ChangeLog 2007-02-01 21:17:35 UTC (rev 2213)
+++ branches/stable/1_0/libselinux/ChangeLog 2007-02-01 21:19:18 UTC (rev 2214)
@@ -1,3 +1,6 @@
+ * Merged patch from Todd Miller to remove sscanf in matchpathcon.c because
+ of the use of the non-standard format %as. (original patch changed
+ for style).
* Merged patch from Todd Miller to fix memory leak in matchpathcon.c.
1.34.1 2007-01-26
Modified: branches/stable/1_0/libselinux/src/matchpathcon.c
===================================================================
--- branches/stable/1_0/libselinux/src/matchpathcon.c 2007-02-01 21:17:35 UTC (rev 2213)
+++ branches/stable/1_0/libselinux/src/matchpathcon.c 2007-02-01 21:19:18 UTC (rev 2214)
@@ -444,7 +444,7 @@
int pass, unsigned lineno)
{
int items, len, regerr, ret;
- char *buf_p;
+ char *buf_p, *ptr;
char *regex, *type, *context;
const char *reg_buf;
char *anchored_regex;
@@ -459,7 +459,18 @@
/* Skip comment lines and empty lines. */
if (*buf_p == '#' || *buf_p == 0)
return 0;
- items = sscanf(line_buf, "%as %as %as", ®ex, &type, &context);
+
+ items = 0;
+ regex = strtok_r(buf_p, " \t", &ptr);
+ if (regex)
+ items += 1;
+ type = strtok_r(NULL, " \t", &ptr);
+ if (type)
+ items += 1;
+ context = strtok_r(NULL, " \t", &ptr);
+ if (context)
+ items += 1;
+
if (items < 2) {
myprintf("%s: line %d is missing fields, skipping\n", path,
lineno);
@@ -470,6 +481,23 @@
type = NULL;
}
+ regex = strdup(regex);
+ if (!regex) {
+ return -1;
+ }
+ if (type) {
+ type = strdup(type);
+ if (!type) {
+ ret = -1;
+ goto finish;
+ }
+ }
+ context = strdup(context);
+ if (!context) {
+ ret = -1;
+ goto finish;
+ }
+
reg_buf = regex;
len = get_stem_from_spec(reg_buf);
if (len && prefix && strncmp(prefix, regex, len)) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|