diff options
Diffstat (limited to 'lib/libc/stdio')
| -rw-r--r-- | lib/libc/stdio/fmemopen.c | 1 | ||||
| -rw-r--r-- | lib/libc/stdio/vfprintf.c | 27 |
2 files changed, 16 insertions, 12 deletions
diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c index 6830dcbe..b1fa0f8a 100644 --- a/lib/libc/stdio/fmemopen.c +++ b/lib/libc/stdio/fmemopen.c @@ -30,6 +30,7 @@ FILE *fmemopen(void *restrict buf, size_t max_size, const char *restrict mode) } else if (mode[0] == 'a') { flags = O_WRONLY | O_CREAT | O_APPEND; } else { + free(f); errno = EINVAL; return NULL; } diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 495fb9ea..90e60f7f 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -325,11 +325,12 @@ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) int pos = 0; if (isnan(val)) { - strcpy(buf, - (*ptr == 'F' || *ptr == 'E' || - *ptr == 'G') ? - "NAN" : - "nan"); + strlcpy(buf, + (*ptr == 'F' || *ptr == 'E' || + *ptr == 'G') ? + "NAN" : + "nan", + sizeof(buf)); l = 3; break; } @@ -341,11 +342,12 @@ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) } else if (flags & FLAG_SPACE) { buf[pos++] = ' '; } - strcpy(buf + pos, - (*ptr == 'F' || *ptr == 'E' || - *ptr == 'G') ? - "INF" : - "inf"); + strlcpy(buf + pos, + (*ptr == 'F' || *ptr == 'E' || + *ptr == 'G') ? + "INF" : + "inf", + sizeof(buf) - pos); l = pos + 3; break; } @@ -607,8 +609,9 @@ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) } if (val == 0.0) { - strcpy(buf + pos, - upper ? "0X0P+0" : "0x0p+0"); + strlcpy(buf + pos, + upper ? "0X0P+0" : "0x0p+0", + sizeof(buf) - pos); l = pos + 6; break; } |
