On 22/05/13 20:05, Osier Yang wrote:
And error out if the casted value is not same with the original
one, which prevents the bug on platform(s) where uid_t/gid_t
has different size with long.
---
src/conf/storage_conf.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index a62629e..a648c6d 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -747,7 +747,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
int defaultmode)
{
char *mode;
- long v;
+ long val;
int ret = -1;
xmlNodePtr relnode;
xmlNodePtr node;
@@ -784,23 +784,26 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
if (virXPathNode("./owner", ctxt) == NULL) {
perms->uid = (uid_t) -1;
} else {
- if (virXPathLong("number(./owner)", ctxt, &v) < 0) {
+ if (virXPathLong("number(./owner)", ctxt, &val) < 0 ||
+ (uid_t)val != val) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed owner element"));
goto error;
}
- perms->uid = (int)v;
+
+ perms->uid = (uid_t)val;
}
if (virXPathNode("./group", ctxt) == NULL) {
perms->gid = (gid_t) -1;
} else {
- if (virXPathLong("number(./group)", ctxt, &v) < 0) {
+ if (virXPathLong("number(./group)", ctxt, &val) < 0 ||
+ (gid_t)val != val) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed group element"));
goto error;
}
- perms->gid = (int)v;
+ perms->gid = (gid_t)val;
}
/* NB, we're ignoring missing labels here - they'll simply inherit */
Rng schema for "owner", and "group":
<element name='owner'>
<choice>
<ref name='unsignedInt'/>
<value>-1</value>
</choice>
</element>
<element name='group'>
<choice>
<ref name='unsignedInt'/>
<value>-1</value>
</choice>
</element>
Which means the patch has to filter out the "-1" when do
"(uid_t)val != val" or "(gid_t)val != val".
So with the attached diff squashed in (will update the commit
log when pushing)
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index a648c6d..082296a 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -44,6 +44,7 @@
#include "viralloc.h"
#include "virfile.h"
#include "virstring.h"
+#include "virlog.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -785,7 +786,8 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
perms->uid = (uid_t) -1;
} else {
if (virXPathLong("number(./owner)", ctxt, &val) < 0 ||
- (uid_t)val != val) {
+ ((uid_t)val != val &&
+ val != -1)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed owner element"));
goto error;
@@ -798,7 +800,8 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
perms->gid = (gid_t) -1;
} else {
if (virXPathLong("number(./group)", ctxt, &val) < 0 ||
- (gid_t)val != val) {
+ ((gid_t) val != val &&
+ val != -1)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed group element"));
goto error;
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list