Hello,

16.07.2013 at 00:31 Lennart Poettering <lenn...@poettering.net> wrote:

+        STRV_FOREACH(x, i->xattrs) {
+                value = *x;
+                name = strsep(&value, "=");

I'd really prefer if we didn't corrupt the string here. Maybe use
strv_split_quoted() here? That handles all the values for you anyway...

You mean strv_split() (I'm splitting by "=")? This has one issue: it
splits by all separator occurrences and I need to split after first one.
If corrupting string is the issue, I can make a copy of it. If you prefer
strv_split(), then I can just join if strv_length > 2.

+        for (n = 0; n < strv_length(tmp); ++n) {
+                len = strlen(tmp[n]);
+                strncpy(xattr, tmp[n], len+1);
+                p = strchr(xattr, '=');
+                if (!p) {
+ log_error("%s: Attribute has incorrect format.", i->path);
+                        return -EBADMSG;
+                }
+                if (p[1] == '\"') {
+                        while (true) {
+                                if (!p)
+                                        p = tmp[n];
+                                else
+                                        p += 2;
+                                p = strchr(p, '\"');
+                                if (p && xattr[p-xattr-1] != '\\')
+                                        break;
+                                p = NULL;
+                                ++n;
+                                if (n == strv_length(tmp))
+                                        break;
+                                len += strlen(tmp[n]) + 1;
+                                strncat(xattr, " ", 1);
+                                strncat(xattr, tmp[n], len);
+                        }
+                }
+                strstrip(xattr);
+                f = i->xattrs;
+                i->xattrs = strv_append(i->xattrs, xattr);
+                if (!i->xattrs){
+                        strv_free(f);
+                        return log_oom();
+                }

For this stuf I'd really prefer using one of our already existing
quoting APIs, like strv_spit_quoted() or FOREACH_WORD_QUOTED or so.

Well, I've tried it in the beginning, but in doesn't work properly in this
case. split_quoted() expects quote on the beginning of a string (ignoring
whitespace occurrences). If there's no such case string will be split using
whitespace. Example of extended attribute with quotes:

user.test="This will \" fail"

So how would you like this case to be solved?

regards,
Maciej

--
Maciej Wereski
Samsung R&D Institute Poland
Samsung Electronics
m.were...@partner.samsung.com
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to