From: Karl MacMillan <kmacmillan@mentalrootkit.com>
To: "Todd C. Miller" <Todd.Miller@sparta.com>
Cc: SE Linux <selinux@tycho.nsa.gov>
Subject: Re: PATCH: libselinux matchpathcon() eliminate %as scanf format
Date: Thu, 01 Feb 2007 16:25:31 -0500 [thread overview]
Message-ID: <45C25ACB.5070203@mentalrootkit.com> (raw)
In-Reply-To: <200701252359.l0PNxMjc011991@tex.courtesan.com>
[-- Attachment #1: Type: text/plain, Size: 2092 bytes --]
Todd C. Miller wrote:
> 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 <kmacmillan@mentalrootkit.com>
I made a few updates for style (the !! thing was too clever for me) and
merged into trunk and stable. Actual merged version is attached.
> --- matchpathcon.c 2007-01-25 14:19:39.000000000 -0500
> +++ matchpathcon.c 2007-01-25 14:21:32.000000000 -0500
> @@ -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,11 @@
> /* Skip comment lines and empty lines. */
> if (*buf_p == '#' || *buf_p == 0)
> return 0;
> - items = sscanf(line_buf, "%as %as %as", ®ex, &type, &context);
> +
> + regex = strtok_r(buf_p, " \t", &ptr);
> + type = strtok_r(NULL, " \t", &ptr);
> + context = strtok_r(NULL, " \t", &ptr);
> + items = !!regex + !!type + !!context;
> if (items < 2) {
> myprintf("%s: line %d is missing fields, skipping\n", path,
> lineno);
> @@ -470,6 +474,15 @@
> type = NULL;
> }
>
> + regex = strdup(regex);
> + if (type != NULL)
> + type = strdup(type);
> + context = strdup(context);
> + if (!!regex + !!type + !!context != items) {
> + ret = -1;
> + goto finish;
> + }
> +
> reg_buf = regex;
> len = get_stem_from_spec(reg_buf);
> if (len && prefix && strncmp(prefix, regex, len)) {
>
> --
> 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.
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 1293 bytes --]
Index: libselinux/src/matchpathcon.c
===================================================================
--- libselinux/src/matchpathcon.c (revision 2209)
+++ libselinux/src/matchpathcon.c (working copy)
@@ -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)) {
prev parent reply other threads:[~2007-02-01 21:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-25 23:59 PATCH: libselinux matchpathcon() eliminate %as scanf format Todd C. Miller
2007-02-01 21:25 ` Karl MacMillan [this message]
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=45C25ACB.5070203@mentalrootkit.com \
--to=kmacmillan@mentalrootkit.com \
--cc=Todd.Miller@sparta.com \
--cc=selinux@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.