WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] tools/xenpaging: fix bug of Segmentation

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] tools/xenpaging: fix bug of Segmentation fault
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 11 Feb 2010 14:50:22 -0800
Delivery-date: Thu, 11 Feb 2010 14:50:50 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1265917805 0
# Node ID eb05347ac47a850927636e0a37c71cab8d1ce919
# Parent  f5da4b37f9ca3b3bb08cf483364f3fe98b6ec2e9
tools/xenpaging: fix bug of Segmentation fault

Segmentation fault occurs in two situations:
1. argc is less than 3
2. xenpaging_init() fault

Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx>
---
 tools/xenpaging/xenpaging.c |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)

diff -r f5da4b37f9ca -r eb05347ac47a tools/xenpaging/xenpaging.c
--- a/tools/xenpaging/xenpaging.c       Thu Feb 11 19:49:31 2010 +0000
+++ b/tools/xenpaging/xenpaging.c       Thu Feb 11 19:50:05 2010 +0000
@@ -212,6 +212,9 @@ int xenpaging_teardown(xenpaging_t *pagi
 {
     int rc;
 
+    if ( paging == NULL )
+        return 0;
+
     /* Tear down domain paging in Xen */
     rc = xc_mem_event_disable(paging->xc_handle, paging->mem_event.domain_id);
     if ( rc != 0 )
@@ -447,19 +450,28 @@ static int evict_victim(xenpaging_t *pag
 
 int main(int argc, char *argv[])
 {
-    domid_t domain_id = atoi(argv[1]);
-    int num_pages = atoi(argv[2]);
+    domid_t domain_id;
+    int num_pages;
     xenpaging_t *paging;
-    xenpaging_victim_t victims[num_pages];
+    xenpaging_victim_t *victims;
     mem_event_request_t req;
     mem_event_response_t rsp;
     int i;
-    int rc;
+    int rc = -1, rc1;
 
     int open_flags = O_CREAT | O_TRUNC | O_RDWR;
     mode_t open_mode = S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | 
S_IWOTH;
     char filename[80];
     int fd;
+
+    if ( argc != 3 ) {
+        fprintf(stderr, "Usage: %s <domain_id> <num_pages>\n", argv[0]);
+       return -1;
+    }
+    domain_id = atoi(argv[1]);
+    num_pages = atoi(argv[2]);
+
+    victims = calloc(num_pages, sizeof(xenpaging_victim_t));
 
     /* Open file */
     sprintf(filename, "page_cache_%d", domain_id);
@@ -586,15 +598,17 @@ int main(int argc, char *argv[])
     }
 
  out:
+    free(victims);
+
     /* Tear down domain paging */
-    rc = xenpaging_teardown(paging);
-    if ( rc != 0 )
-    {
+    rc1 = xenpaging_teardown(paging);
+    if ( rc1 != 0 )
         ERROR("Error tearing down paging");
-        exit(1);
-    }
-
-    return 0;
+
+    if ( rc == 0 )
+        rc = rc1;
+
+    return rc;
 }
 
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] tools/xenpaging: fix bug of Segmentation fault, Xen patchbot-unstable <=