Re: [libvirt] [PATCH] conf: forbid negative values in virDomainParseScaledValue

2014-10-30 Thread Martin Kletzander

On Wed, Oct 29, 2014 at 04:18:42PM -0600, Eric Blake wrote:

On 10/29/2014 10:35 AM, Martin Kletzander wrote:

It makes sense for none of the callers to have negative value as an
output and, fortunately, if anyone tried defining domain with negative
memory or any other value parsed by virDomainParseScaledValue(), the
resulting value was 0.  That means we can error out during parsing as
it won't break anything.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1155843

Signed-off-by: Martin Kletzander mklet...@redhat.com
---
it won't break anything -- famous last words?

 src/conf/domain_conf.c | 25 -
 1 file changed, 16 insertions(+), 9 deletions(-)


ACK.  Sounds like a bug fix, and therefore safe for 1.2.10



Um... on one hand it is, but on the other one this is bug that's been
around since we introduced @unit (almost forever) :-)  Anyway, the
patch is pretty small and it affects nothing else, so I pushed it.
Thanks for the review.

Martin


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] conf: forbid negative values in virDomainParseScaledValue

2014-10-29 Thread Martin Kletzander
It makes sense for none of the callers to have negative value as an
output and, fortunately, if anyone tried defining domain with negative
memory or any other value parsed by virDomainParseScaledValue(), the
resulting value was 0.  That means we can error out during parsing as
it won't break anything.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1155843

Signed-off-by: Martin Kletzander mklet...@redhat.com
---
it won't break anything -- famous last words?

 src/conf/domain_conf.c | 25 -
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 39befb0..a351382 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6334,28 +6334,34 @@ virDomainParseScaledValue(const char *xpath,
 {
 char *xpath_full = NULL;
 char *unit = NULL;
+char *bytes_str = NULL;
 int ret = -1;
 unsigned long long bytes;

 *val = 0;
 if (virAsprintf(xpath_full, string(%s), xpath)  0)
 goto cleanup;
-ret = virXPathULongLong(xpath_full, ctxt, bytes);
-if (ret  0) {
-if (ret == -2)
-virReportError(VIR_ERR_XML_ERROR,
-   _(could not parse element %s),
-   xpath);
-else if (required)
+
+bytes_str = virXPathString(xpath_full, ctxt);
+if (!bytes_str) {
+if (!required) {
+ret = 0;
+} else {
 virReportError(VIR_ERR_XML_ERROR,
_(missing element %s),
xpath);
-else
-ret = 0;
+}
 goto cleanup;
 }
 VIR_FREE(xpath_full);

+if (virStrToLong_ullp(bytes_str, NULL, 10, bytes)  0) {
+virReportError(VIR_ERR_XML_ERROR,
+   _(Invalid value '%s' for element '%s'),
+   bytes_str, xpath);
+goto cleanup;
+}
+
 if (virAsprintf(xpath_full, string(%s/@unit), xpath)  0)
 goto cleanup;
 unit = virXPathString(xpath_full, ctxt);
@@ -6366,6 +6372,7 @@ virDomainParseScaledValue(const char *xpath,
 *val = bytes;
 ret = 1;
  cleanup:
+VIR_FREE(bytes_str);
 VIR_FREE(xpath_full);
 VIR_FREE(unit);
 return ret;
--
2.1.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] conf: forbid negative values in virDomainParseScaledValue

2014-10-29 Thread Eric Blake
On 10/29/2014 10:35 AM, Martin Kletzander wrote:
 It makes sense for none of the callers to have negative value as an
 output and, fortunately, if anyone tried defining domain with negative
 memory or any other value parsed by virDomainParseScaledValue(), the
 resulting value was 0.  That means we can error out during parsing as
 it won't break anything.
 
 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1155843
 
 Signed-off-by: Martin Kletzander mklet...@redhat.com
 ---
 it won't break anything -- famous last words?
 
  src/conf/domain_conf.c | 25 -
  1 file changed, 16 insertions(+), 9 deletions(-)

ACK.  Sounds like a bug fix, and therefore safe for 1.2.10

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list