git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fish: In guestfish(1) turn command references into links.
[libguestfs.git]
/
daemon
/
sfdisk.c
diff --git
a/daemon/sfdisk.c
b/daemon/sfdisk.c
index
f1726fc
..
20d7dc8
100644
(file)
--- a/
daemon/sfdisk.c
+++ b/
daemon/sfdisk.c
@@
-1,5
+1,5
@@
/* libguestfs - the guestfsd daemon
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@
-30,17
+30,15
@@
#include "actions.h"
static int
#include "actions.h"
static int
-sfdisk (char *device, int n, int cyls, int heads, int sectors,
- const char *extra_flag,
-
char * const* const
lines)
+sfdisk (c
onst c
har *device, int n, int cyls, int heads, int sectors,
+
const char *extra_flag,
+
char *const *
lines)
{
FILE *fp;
char buf[256];
int i;
{
FILE *fp;
char buf[256];
int i;
- IS_DEVICE (device, -1);
-
- strcpy (buf, "/sbin/sfdisk");
+ strcpy (buf, "sfdisk");
if (n > 0)
sprintf (buf + strlen (buf), " -N %d", n);
if (n > 0)
sprintf (buf + strlen (buf), " -N %d", n);
@@
-50,10
+48,23
@@
sfdisk (char *device, int n, int cyls, int heads, int sectors,
sprintf (buf + strlen (buf), " -H %d", heads);
if (sectors)
sprintf (buf + strlen (buf), " -S %d", sectors);
sprintf (buf + strlen (buf), " -H %d", heads);
if (sectors)
sprintf (buf + strlen (buf), " -S %d", sectors);
- if (extra_flag)
+
+ /* The above are all guaranteed to fit in the fixed-size buffer.
+ However, extra_flag and device have no restrictions,
+ so we must check. */
+
+ if (extra_flag) {
+ if (strlen (buf) + 1 + strlen (extra_flag) >= sizeof buf) {
+ reply_with_error ("internal buffer overflow: sfdisk extra_flag too long");
+ return -1;
+ }
sprintf (buf + strlen (buf), " %s", extra_flag);
sprintf (buf + strlen (buf), " %s", extra_flag);
+ }
- /* Safe because of IS_DEVICE above: */
+ if (strlen (buf) + 1 + strlen (device) >= sizeof buf) {
+ reply_with_error ("internal buffer overflow: sfdisk device name too long");
+ return -1;
+ }
sprintf (buf + strlen (buf), " %s", device);
if (verbose)
sprintf (buf + strlen (buf), " %s", device);
if (verbose)
@@
-61,13
+72,13
@@
sfdisk (char *device, int n, int cyls, int heads, int sectors,
fp = popen (buf, "w");
if (fp == NULL) {
fp = popen (buf, "w");
if (fp == NULL) {
- reply_with_perror (buf);
+ reply_with_perror (
"failed to open pipe: %s",
buf);
return -1;
}
for (i = 0; lines[i] != NULL; ++i) {
if (fprintf (fp, "%s\n", lines[i]) < 0) {
return -1;
}
for (i = 0; lines[i] != NULL; ++i) {
if (fprintf (fp, "%s\n", lines[i]) < 0) {
- reply_with_perror (buf);
+ reply_with_perror (
"failed to write to pipe: %s",
buf);
pclose (fp);
return -1;
}
pclose (fp);
return -1;
}
@@
-84,38
+95,36
@@
sfdisk (char *device, int n, int cyls, int heads, int sectors,
}
int
}
int
-do_sfdisk (char *device, int cyls, int heads, int sectors,
-
char *
*lines)
+do_sfdisk (c
onst c
har *device, int cyls, int heads, int sectors,
+
char *const
*lines)
{
return sfdisk (device, 0, cyls, heads, sectors, NULL, lines);
}
int
{
return sfdisk (device, 0, cyls, heads, sectors, NULL, lines);
}
int
-do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors,
- char *line)
+do_sfdisk_N (c
onst c
har *device, int n, int cyls, int heads, int sectors,
+
const
char *line)
{
{
- c
onst char *
lines[2] = { line, NULL };
+ c
har const *const
lines[2] = { line, NULL };
- return sfdisk (device, n, cyls, heads, sectors, NULL, lines);
+ return sfdisk (device, n, cyls, heads, sectors, NULL,
(void *)
lines);
}
int
}
int
-do_sfdiskM (c
har *device, char *
*lines)
+do_sfdiskM (c
onst char *device, char *const
*lines)
{
return sfdisk (device, 0, 0, 0, 0, "-uM", lines);
}
static char *
{
return sfdisk (device, 0, 0, 0, 0, "-uM", lines);
}
static char *
-sfdisk_flag (char *device, const char *flag)
+sfdisk_flag (c
onst c
har *device, const char *flag)
{
char *out, *err;
int r;
{
char *out, *err;
int r;
- IS_DEVICE (device, NULL);
-
- r = command (&out, &err, "/sbin/sfdisk", flag, device, NULL);
+ r = command (&out, &err, "sfdisk", flag, device, NULL);
if (r == -1) {
if (r == -1) {
- reply_with_error ("
sfdisk:
%s: %s", device, err);
+ reply_with_error ("%s: %s", device, err);
free (out);
free (err);
return NULL;
free (out);
free (err);
return NULL;
@@
-129,19
+138,19
@@
sfdisk_flag (char *device, const char *flag)
}
char *
}
char *
-do_sfdisk_l (char *device)
+do_sfdisk_l (c
onst c
har *device)
{
return sfdisk_flag (device, "-l");
}
char *
{
return sfdisk_flag (device, "-l");
}
char *
-do_sfdisk_kernel_geometry (char *device)
+do_sfdisk_kernel_geometry (c
onst c
har *device)
{
return sfdisk_flag (device, "-g");
}
char *
{
return sfdisk_flag (device, "-g");
}
char *
-do_sfdisk_disk_geometry (char *device)
+do_sfdisk_disk_geometry (c
onst c
har *device)
{
return sfdisk_flag (device, "-G");
}
{
return sfdisk_flag (device, "-G");
}