hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/scsi/scsi_proc.c
....@@ -311,7 +311,7 @@
311311 size_t length, loff_t *ppos)
312312 {
313313 int host, channel, id, lun;
314
- char *buffer, *p;
314
+ char *buffer, *end, *p;
315315 int err;
316316
317317 if (!buf || length > PAGE_SIZE)
....@@ -326,10 +326,14 @@
326326 goto out;
327327
328328 err = -EINVAL;
329
- if (length < PAGE_SIZE)
330
- buffer[length] = '\0';
331
- else if (buffer[PAGE_SIZE-1])
332
- goto out;
329
+ if (length < PAGE_SIZE) {
330
+ end = buffer + length;
331
+ *end = '\0';
332
+ } else {
333
+ end = buffer + PAGE_SIZE - 1;
334
+ if (*end)
335
+ goto out;
336
+ }
333337
334338 /*
335339 * Usage: echo "scsi add-single-device 0 1 2 3" >/proc/scsi/scsi
....@@ -338,10 +342,10 @@
338342 if (!strncmp("scsi add-single-device", buffer, 22)) {
339343 p = buffer + 23;
340344
341
- host = simple_strtoul(p, &p, 0);
342
- channel = simple_strtoul(p + 1, &p, 0);
343
- id = simple_strtoul(p + 1, &p, 0);
344
- lun = simple_strtoul(p + 1, &p, 0);
345
+ host = (p < end) ? simple_strtoul(p, &p, 0) : 0;
346
+ channel = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
347
+ id = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
348
+ lun = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
345349
346350 err = scsi_add_single_device(host, channel, id, lun);
347351
....@@ -352,10 +356,10 @@
352356 } else if (!strncmp("scsi remove-single-device", buffer, 25)) {
353357 p = buffer + 26;
354358
355
- host = simple_strtoul(p, &p, 0);
356
- channel = simple_strtoul(p + 1, &p, 0);
357
- id = simple_strtoul(p + 1, &p, 0);
358
- lun = simple_strtoul(p + 1, &p, 0);
359
+ host = (p < end) ? simple_strtoul(p, &p, 0) : 0;
360
+ channel = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
361
+ id = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
362
+ lun = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
359363
360364 err = scsi_remove_single_device(host, channel, id, lun);
361365 }