@@ -406,7 +406,7 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
size_t length, loff_t *ppos)
{
int host, channel, id, lun;
- char *buffer, *p;
+ char *buffer, *end, *p;
int err;
if (!buf || length > PAGE_SIZE)
@@ -421,10 +421,14 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
goto out;
err = -EINVAL;
- if (length < PAGE_SIZE)
- buffer[length] = '\0';
- else if (buffer[PAGE_SIZE-1])
- goto out;
+ if (length < PAGE_SIZE) {
+ end = buffer + length;
+ *end = '\0';
+ } else {
+ end = buffer + PAGE_SIZE - 1;
+ if (*end)
+ goto out;
+ }
/*
* Usage: echo "scsi add-single-device 0 1 2 3" >/proc/scsi/scsi
@@ -432,11 +436,22 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
*/
if (!strncmp("scsi add-single-device", buffer, 22)) {
p = buffer + 23;
+ if (p >= end)
+ goto out;
host = simple_strtoul(p, &p, 0);
- channel = simple_strtoul(p + 1, &p, 0);
- id = simple_strtoul(p + 1, &p, 0);
- lun = simple_strtoul(p + 1, &p, 0);
+ if (++p >= end)
+ goto out;
+
+ channel = simple_strtoul(p, &p, 0);
+ if (++p >= end)
+ goto out;
+
+ id = simple_strtoul(p, &p, 0);
+ if (++p >= end)
+ goto out;
+
+ lun = simple_strtoul(p, &p, 0);
err = scsi_add_single_device(host, channel, id, lun);
@@ -446,11 +461,22 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
*/
} else if (!strncmp("scsi remove-single-device", buffer, 25)) {
p = buffer + 26;
+ if (p >= end)
+ goto out;
host = simple_strtoul(p, &p, 0);
- channel = simple_strtoul(p + 1, &p, 0);
- id = simple_strtoul(p + 1, &p, 0);
- lun = simple_strtoul(p + 1, &p, 0);
+ if (++p >= end)
+ goto out;
+
+ channel = simple_strtoul(p, &p, 0);
+ if (++p >= end)
+ goto out;
+
+ id = simple_strtoul(p, &p, 0);
+ if (++p >= end)
+ goto out;
+
+ lun = simple_strtoul(p, &p, 0);
err = scsi_remove_single_device(host, channel, id, lun);
}