Skip to content

Commit 6d3fbe9

Browse files
tiwaiDominik Brodowski
authored andcommitted
pcmcia: Use scnprintf() for avoiding potential buffer overflow
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 <[email protected]> Signed-off-by: Dominik Brodowski <[email protected]>
1 parent 7c8c567 commit 6d3fbe9

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

drivers/pcmcia/rsrc_nonstatic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ static ssize_t show_io_db(struct device *dev,
10761076
for (p = data->io_db.next; p != &data->io_db; p = p->next) {
10771077
if (ret > (PAGE_SIZE - 10))
10781078
continue;
1079-
ret += snprintf(&buf[ret], (PAGE_SIZE - ret - 1),
1079+
ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1),
10801080
"0x%08lx - 0x%08lx\n",
10811081
((unsigned long) p->base),
10821082
((unsigned long) p->base + p->num - 1));
@@ -1133,7 +1133,7 @@ static ssize_t show_mem_db(struct device *dev,
11331133
p = p->next) {
11341134
if (ret > (PAGE_SIZE - 10))
11351135
continue;
1136-
ret += snprintf(&buf[ret], (PAGE_SIZE - ret - 1),
1136+
ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1),
11371137
"0x%08lx - 0x%08lx\n",
11381138
((unsigned long) p->base),
11391139
((unsigned long) p->base + p->num - 1));
@@ -1142,7 +1142,7 @@ static ssize_t show_mem_db(struct device *dev,
11421142
for (p = data->mem_db.next; p != &data->mem_db; p = p->next) {
11431143
if (ret > (PAGE_SIZE - 10))
11441144
continue;
1145-
ret += snprintf(&buf[ret], (PAGE_SIZE - ret - 1),
1145+
ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1),
11461146
"0x%08lx - 0x%08lx\n",
11471147
((unsigned long) p->base),
11481148
((unsigned long) p->base + p->num - 1));

drivers/pcmcia/yenta_socket.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,23 @@ static ssize_t show_yenta_registers(struct device *yentadev, struct device_attri
180180
for (i = 0; i < 0x24; i += 4) {
181181
unsigned val;
182182
if (!(i & 15))
183-
offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
183+
offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
184184
val = cb_readl(socket, i);
185-
offset += snprintf(buf + offset, PAGE_SIZE - offset, " %08x", val);
185+
offset += scnprintf(buf + offset, PAGE_SIZE - offset, " %08x", val);
186186
}
187187

188-
offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:");
188+
offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:");
189189
for (i = 0; i < 0x45; i++) {
190190
unsigned char val;
191191
if (!(i & 7)) {
192192
if (i & 8) {
193193
memcpy(buf + offset, " -", 2);
194194
offset += 2;
195195
} else
196-
offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
196+
offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
197197
}
198198
val = exca_readb(socket, i);
199-
offset += snprintf(buf + offset, PAGE_SIZE - offset, " %02x", val);
199+
offset += scnprintf(buf + offset, PAGE_SIZE - offset, " %02x", val);
200200
}
201201
buf[offset++] = '\n';
202202
return offset;

0 commit comments

Comments
 (0)