Skip to content

Commit 5eff88d

Browse files
Villemoesardbiesheuvel
authored andcommitted
efi: cper: fix scnprintf() use in cper_mem_err_location()
The last two if-clauses fail to update n, so whatever they might have written at &msg[n] would be cut off by the final nul-termination. That nul-termination is redundant; scnprintf(), just like snprintf(), guarantees a nul-terminated output buffer, provided the buffer size is positive. And there's no need to discount one byte from the initial buffer; vsnprintf() expects to be given the full buffer size - it's not going to write the nul-terminator one beyond the given (buffer, size) pair. Signed-off-by: Rasmus Villemoes <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent e73f0f0 commit 5eff88d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/firmware/efi/cper.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg)
221221
return 0;
222222

223223
n = 0;
224-
len = CPER_REC_LEN - 1;
224+
len = CPER_REC_LEN;
225225
if (mem->validation_bits & CPER_MEM_VALID_NODE)
226226
n += scnprintf(msg + n, len - n, "node: %d ", mem->node);
227227
if (mem->validation_bits & CPER_MEM_VALID_CARD)
@@ -258,13 +258,12 @@ static int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg)
258258
n += scnprintf(msg + n, len - n, "responder_id: 0x%016llx ",
259259
mem->responder_id);
260260
if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID)
261-
scnprintf(msg + n, len - n, "target_id: 0x%016llx ",
262-
mem->target_id);
261+
n += scnprintf(msg + n, len - n, "target_id: 0x%016llx ",
262+
mem->target_id);
263263
if (mem->validation_bits & CPER_MEM_VALID_CHIP_ID)
264-
scnprintf(msg + n, len - n, "chip_id: %d ",
265-
mem->extended >> CPER_MEM_CHIP_ID_SHIFT);
264+
n += scnprintf(msg + n, len - n, "chip_id: %d ",
265+
mem->extended >> CPER_MEM_CHIP_ID_SHIFT);
266266

267-
msg[n] = '\0';
268267
return n;
269268
}
270269

0 commit comments

Comments
 (0)