]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
pcmcia: Use scnprintf() for avoiding potential buffer overflow
authorTakashi Iwai <tiwai@suse.de>
Wed, 11 Mar 2020 09:04:26 +0000 (10:04 +0100)
committerDominik Brodowski <linux@dominikbrodowski.net>
Sat, 14 Mar 2020 13:32:04 +0000 (14:32 +0100)
Since snprintf() returns the would-be-output size instead of the
actual output size, the succeeding calls may go beyond the given
buffer limit.  Fix it by replacing with scnprintf().

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
drivers/pcmcia/rsrc_nonstatic.c
drivers/pcmcia/yenta_socket.c

index 9e6922c08ef6246f75f8fc1127bdccce8d4b3972..3b05760e69d6213ecb48ae659d27ce6ebdc5a00a 100644 (file)
@@ -1076,7 +1076,7 @@ static ssize_t show_io_db(struct device *dev,
        for (p = data->io_db.next; p != &data->io_db; p = p->next) {
                if (ret > (PAGE_SIZE - 10))
                        continue;
-               ret += snprintf(&buf[ret], (PAGE_SIZE - ret - 1),
+               ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1),
                                "0x%08lx - 0x%08lx\n",
                                ((unsigned long) p->base),
                                ((unsigned long) p->base + p->num - 1));
@@ -1133,7 +1133,7 @@ static ssize_t show_mem_db(struct device *dev,
             p = p->next) {
                if (ret > (PAGE_SIZE - 10))
                        continue;
-               ret += snprintf(&buf[ret], (PAGE_SIZE - ret - 1),
+               ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1),
                                "0x%08lx - 0x%08lx\n",
                                ((unsigned long) p->base),
                                ((unsigned long) p->base + p->num - 1));
@@ -1142,7 +1142,7 @@ static ssize_t show_mem_db(struct device *dev,
        for (p = data->mem_db.next; p != &data->mem_db; p = p->next) {
                if (ret > (PAGE_SIZE - 10))
                        continue;
-               ret += snprintf(&buf[ret], (PAGE_SIZE - ret - 1),
+               ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1),
                                "0x%08lx - 0x%08lx\n",
                                ((unsigned long) p->base),
                                ((unsigned long) p->base + p->num - 1));
index 49b1c6a1bdbea8cdb8d59417a79ec724a1e66d1d..bf6529b0b5b092f0b035fe9c2f2d6825da06429e 100644 (file)
@@ -180,12 +180,12 @@ static ssize_t show_yenta_registers(struct device *yentadev, struct device_attri
        for (i = 0; i < 0x24; i += 4) {
                unsigned val;
                if (!(i & 15))
-                       offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
+                       offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
                val = cb_readl(socket, i);
-               offset += snprintf(buf + offset, PAGE_SIZE - offset, " %08x", val);
+               offset += scnprintf(buf + offset, PAGE_SIZE - offset, " %08x", val);
        }
 
-       offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:");
+       offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:");
        for (i = 0; i < 0x45; i++) {
                unsigned char val;
                if (!(i & 7)) {
@@ -193,10 +193,10 @@ static ssize_t show_yenta_registers(struct device *yentadev, struct device_attri
                                memcpy(buf + offset, " -", 2);
                                offset += 2;
                        } else
-                               offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
+                               offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
                }
                val = exca_readb(socket, i);
-               offset += snprintf(buf + offset, PAGE_SIZE - offset, " %02x", val);
+               offset += scnprintf(buf + offset, PAGE_SIZE - offset, " %02x", val);
        }
        buf[offset++] = '\n';
        return offset;