summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-06-02 15:35:58 +0100
committerRichard Jones <rjones@redhat.com>2010-06-02 15:35:58 +0100
commitcbb026036826f2ab40237aec0b0c5453b859625d (patch)
tree7840312644599285c1e9ba90df7d55c4cfe44103
parent3ab2d089f3eb34562bc2c9ce4310869b46c69d70 (diff)
downloadlibguestfs-cbb026036826f2ab40237aec0b0c5453b859625d.tar.gz
libguestfs-cbb026036826f2ab40237aec0b0c5453b859625d.tar.xz
libguestfs-cbb026036826f2ab40237aec0b0c5453b859625d.zip
parted: Check partition number >= 1 in several calls.
-rw-r--r--daemon/parted.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/daemon/parted.c b/daemon/parted.c
index fe68d1d9..2f928b05 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);