From: Steve Dickson <SteveD@redhat.com>
To: nfs@lists.sourceforge.net
Subject: [PATCH 11/11] nfs-utils: mount: Fixed collision between commas in options
Date: Mon, 26 Feb 2007 06:20:41 -0500 [thread overview]
Message-ID: <45E2C289.30506@RedHat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 0 bytes --]
[-- Attachment #2: patch-11.dif --]
[-- Type: text/x-patch, Size: 3515 bytes --]
commit 96a3ceb3d35bf5edcb9446aded8375d3b98b4f5b
Author: Cory Olmo <colmo@TrustedCS.com>
Date: Sat Feb 24 16:20:40 2007 -0500
This patch avoid the collision between commas in security contexts and the
delimiter betweeen mount options.
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Cory Olmo <colmo@TrustedCS.com>
diff --git a/utils/mount/mount.c b/utils/mount/mount.c
index b3d3696..f22747b 100644
--- a/utils/mount/mount.c
+++ b/utils/mount/mount.c
@@ -285,18 +285,30 @@ static void parse_opts (const char *options, int *flags, char **extra_opts)
{
if (options != NULL) {
char *opts = xstrdup(options);
- char *opt;
- int len = strlen(opts) + 20;
-
+ char *opt, *p;
+ int len = strlen(opts) + 256;
+ int open_quote = 0;
+
*extra_opts = xmalloc(len);
**extra_opts = '\0';
- for (opt = strtok(opts, ","); opt; opt = strtok(NULL, ","))
- parse_opt(opt, flags, *extra_opts, len);
-
+ for (p=opts, opt=NULL; p && *p; p++) {
+ if (!opt)
+ opt = p; /* begin of the option item */
+ if (*p == '"')
+ open_quote ^= 1; /* reverse the status */
+ if (open_quote)
+ continue; /* still in quoted block */
+ if (*p == ',')
+ *p = '\0'; /* terminate the option item */
+ /* end of option item or last item */
+ if (*p == '\0' || *(p+1) == '\0') {
+ parse_opt(opt, flags, *extra_opts, len);
+ opt = NULL;
+ }
+ }
free(opts);
}
-
}
/*
diff --git a/utils/mount/nfsmount.c b/utils/mount/nfsmount.c
index 3ca9b80..08a8ac1 100644
--- a/utils/mount/nfsmount.c
+++ b/utils/mount/nfsmount.c
@@ -548,15 +548,31 @@ parse_options(char *old_opts, struct nfs_mount_data *data,
struct pmap *mnt_pmap = &mnt_server->pmap;
struct pmap *nfs_pmap = &nfs_server->pmap;
int len;
- char *opt, *opteq;
+ char *opt, *opteq, *p, *opt_b;
char *mounthost = NULL;
char cbuf[128];
+ int open_quote = 0;
data->flags = 0;
*bg = 0;
len = strlen(new_opts);
- for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) {
+ for (p=old_opts, opt_b=NULL; p && *p; p++) {
+ if (!opt_b)
+ opt_b = p; /* begin of the option item */
+ if (*p == '"')
+ open_quote ^= 1; /* reverse the status */
+ if (open_quote)
+ continue; /* still in quoted block */
+ if (*p == ',')
+ *p = '\0'; /* terminate the option item */
+ if (*p == '\0' || *(p+1) == '\0') {
+ opt = opt_b; /* opt is useful now */
+ opt_b = NULL;
+ }
+ else
+ continue; /* still somewhere in the option item */
+
if (strlen(opt) >= sizeof(cbuf))
goto bad_parameter;
if ((opteq = strchr(opt, '=')) && isdigit(opteq[1])) {
@@ -671,13 +687,23 @@ parse_options(char *old_opts, struct nfs_mount_data *data,
strcspn(opteq+1," \t\n\r,"));
else if (!strcmp(opt, "context")) {
char *context = opteq + 1;
+ int ctxlen = strlen(context);
- if (strlen(context) > NFS_MAX_CONTEXT_LEN) {
+ if (ctxlen > NFS_MAX_CONTEXT_LEN) {
printf(_("context parameter exceeds limit of %d\n"),
NFS_MAX_CONTEXT_LEN);
goto bad_parameter;
}
- strncpy(data->context, context, NFS_MAX_CONTEXT_LEN);
+ /* The context string is in the format of
+ * "system_u:object_r:...". We only want
+ * the context str between the quotes.
+ */
+ if (*context == '"')
+ strncpy(data->context, context+1,
+ ctxlen-2);
+ else
+ strncpy(data->context, context,
+ NFS_MAX_CONTEXT_LEN);
} else if (!sloppy)
goto bad_parameter;
sprintf(cbuf, "%s=%s,", opt, opteq+1);
[-- Attachment #3: Type: text/plain, Size: 345 bytes --]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
[-- Attachment #4: Type: text/plain, Size: 140 bytes --]
_______________________________________________
NFS maillist - NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs
next reply other threads:[~2007-02-26 11:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-26 11:20 Steve Dickson [this message]
2007-02-27 6:35 ` [PATCH 11/11] nfs-utils: mount: Fixed collision between commas in options Neil Brown
2007-02-27 9:34 ` Karel Zak
2007-02-27 11:45 ` Karel Zak
2007-02-28 23:33 ` Neil Brown
2007-03-01 9:02 ` Karel Zak
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=45E2C289.30506@RedHat.com \
--to=steved@redhat.com \
--cc=nfs@lists.sourceforge.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox