]> xenbits.xensource.com Git - libvirt.git/commitdiff
xen: fix parsing xend http response
authorJim Fehlig <jfehlig@suse.com>
Wed, 29 Jan 2014 01:15:48 +0000 (18:15 -0700)
committerJim Fehlig <jfehlig@suse.com>
Wed, 29 Jan 2014 01:32:49 +0000 (18:32 -0700)
Commit df36af58 broke parsing of http response from xend.  The prior
use of atoi() would happily parse e.g. a string containing "200 OK\r\n",
whereas virStrToLong_i() will fail when called with a NULL end_ptr.
Change the calls to virStrToLong_i() to provide a non-NULL end_ptr.

src/xen/xend_internal.c

index 87e77a6b0cc7a643697081fbdea58faa19d691d2..25137b87c83aa615d475f21b71f9b8bc80f59535 100644 (file)
@@ -282,6 +282,7 @@ xend_req(int fd, char **content)
     size_t buffer_size = 4096;
     int content_length = 0;
     int retcode = 0;
+    char *end_ptr;
 
     if (VIR_ALLOC_N(buffer, buffer_size) < 0)
         return -1;
@@ -291,13 +292,13 @@ xend_req(int fd, char **content)
             break;
 
         if (istartswith(buffer, "Content-Length: ")) {
-            if (virStrToLong_i(buffer + 16, NULL, 10, &content_length) < 0) {
+            if (virStrToLong_i(buffer + 16, &end_ptr, 10, &content_length) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("failed to parse Xend response content length"));
                 return -1;
             }
         } else if (istartswith(buffer, "HTTP/1.1 ")) {
-            if (virStrToLong_i(buffer + 9, NULL, 10, &retcode) < 0) {
+            if (virStrToLong_i(buffer + 9, &end_ptr, 10, &retcode) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("failed to parse Xend response return code"));
                 return -1;