mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-27 08:10:07 +08:00
lib/vsnprintf.c: correct boundary conditions
Correct the boundary conditions in lib/vsnprintf.c; as it was we could have an undetected one-byte overwrite.
This commit is contained in:
parent
304b605563
commit
43827654ac
@ -30,17 +30,17 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
}
|
||||
|
||||
rv = vsprintf(snprintf_buffer, format, ap);
|
||||
if (rv > BUFFER_SIZE) {
|
||||
if (rv >= BUFFER_SIZE) {
|
||||
nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
|
||||
"snprintf buffer overflow");
|
||||
}
|
||||
|
||||
if (rv < (int)size-1)
|
||||
bytes = rv;
|
||||
else
|
||||
bytes = size-1;
|
||||
|
||||
if (size > 0) {
|
||||
if ((size_t)rv < size-1)
|
||||
bytes = rv;
|
||||
else
|
||||
bytes = size-1;
|
||||
|
||||
memcpy(str, snprintf_buffer, bytes);
|
||||
str[bytes] = '\0';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user