[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] parted: Check partition number >= 1 in several calls.



This patch depends on the previous one, but is logically independent
from it.  It simply adds checks that the partition number >= 1 for all
those part-* calls that take a partition number.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
>From cbb026036826f2ab40237aec0b0c5453b859625d Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones redhat com>
Date: Wed, 2 Jun 2010 15:35:58 +0100
Subject: [PATCH] parted: Check partition number >= 1 in several calls.

---
 daemon/parted.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/daemon/parted.c b/daemon/parted.c
index fe68d1d..2f928b0 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -161,6 +161,11 @@ do_part_add (const char *device, const char *prlogex,
 int
 do_part_del (const char *device, int partnum)
 {
+  if (partnum <= 0) {
+    reply_with_error ("partition number must be >= 1");
+    return -1;
+  }
+
   char partnum_str[16];
   snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
 
@@ -210,6 +215,11 @@ do_part_disk (const char *device, const char *parttype)
 int
 do_part_set_bootable (const char *device, int partnum, int bootable)
 {
+  if (partnum <= 0) {
+    reply_with_error ("partition number must be >= 1");
+    return -1;
+  }
+
   char partstr[16];
 
   snprintf (partstr, sizeof partstr, "%d", partnum);
@@ -225,6 +235,11 @@ do_part_set_bootable (const char *device, int partnum, int bootable)
 int
 do_part_set_name (const char *device, int partnum, const char *name)
 {
+  if (partnum <= 0) {
+    reply_with_error ("partition number must be >= 1");
+    return -1;
+  }
+
   char partstr[16];
 
   snprintf (partstr, sizeof partstr, "%d", partnum);
@@ -529,6 +544,11 @@ do_part_list (const char *device)
 int
 do_part_get_bootable (const char *device, int partnum)
 {
+  if (partnum <= 0) {
+    reply_with_error ("partition number must be >= 1");
+    return -1;
+  }
+
   int parted_has_m_opt = test_parted_m_opt ();
   if (parted_has_m_opt == -1)
     return -1;
@@ -622,6 +642,11 @@ do_part_get_bootable (const char *device, int partnum)
 int
 do_part_get_mbr_id (const char *device, int partnum)
 {
+  if (partnum <= 0) {
+    reply_with_error ("partition number must be >= 1");
+    return -1;
+  }
+
   char partnum_str[16];
   snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
 
@@ -653,6 +678,11 @@ do_part_get_mbr_id (const char *device, int partnum)
 int
 do_part_set_mbr_id (const char *device, int partnum, int idbyte)
 {
+  if (partnum <= 0) {
+    reply_with_error ("partition number must be >= 1");
+    return -1;
+  }
+
   char partnum_str[16];
   snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
 
-- 
1.6.6.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]