mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Warn on sprintf use.
This commit is contained in:
parent
d668c5558e
commit
36c70760a0
2 changed files with 18 additions and 0 deletions
|
@ -218,6 +218,18 @@ particular problem.
|
||||||
|
|
||||||
Sortix currently provides this function for compatibility reasons.
|
Sortix currently provides this function for compatibility reasons.
|
||||||
|
|
||||||
|
sprintf
|
||||||
|
-------
|
||||||
|
|
||||||
|
The sprintf function is dangerous as it can be hard to predict the length of the
|
||||||
|
output string safely. A mistake can easily end in security vulnerabilities and
|
||||||
|
undefined behavior. Use the snprintf function instead as it knows the size of
|
||||||
|
the destination buffer and safely truncates in the error case. Such truncation
|
||||||
|
can be detected by the cacller. Use the asprintf function or another approach
|
||||||
|
if determinining the output length is hard.
|
||||||
|
|
||||||
|
Sortix currently provides this function for compatibility reasons.
|
||||||
|
|
||||||
strings.h
|
strings.h
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,9 @@ int rename(const char* oldname, const char* newname);
|
||||||
void rewind(FILE* stream);
|
void rewind(FILE* stream);
|
||||||
void setbuf(FILE* __restrict stream, char* __restrict buf);
|
void setbuf(FILE* __restrict stream, char* __restrict buf);
|
||||||
int setvbuf(FILE* __restrict stream, char* __restrict buf, int type, size_t size);
|
int setvbuf(FILE* __restrict stream, char* __restrict buf, int type, size_t size);
|
||||||
|
#if !defined(__is_sortix_libc) /* not a warning inside libc */
|
||||||
|
__attribute__((__warning__("sprintf() is dangerous, use snprintf()")))
|
||||||
|
#endif
|
||||||
int sprintf(char* __restrict s, const char* __restrict format, ...)
|
int sprintf(char* __restrict s, const char* __restrict format, ...)
|
||||||
__attribute__((__format__ (printf, 2, 3)));
|
__attribute__((__format__ (printf, 2, 3)));
|
||||||
int scanf(const char* __restrict format, ...)
|
int scanf(const char* __restrict format, ...)
|
||||||
|
@ -178,6 +181,9 @@ int vfprintf(FILE* __restrict stream, const char* __restrict format, __gnuc_va_l
|
||||||
__attribute__((__format__ (printf, 2, 0)));
|
__attribute__((__format__ (printf, 2, 0)));
|
||||||
int vprintf(const char* __restrict format, __gnuc_va_list ap)
|
int vprintf(const char* __restrict format, __gnuc_va_list ap)
|
||||||
__attribute__((__format__ (printf, 1, 0)));
|
__attribute__((__format__ (printf, 1, 0)));
|
||||||
|
#if !defined(__is_sortix_libc) /* not a warning inside libc */
|
||||||
|
__attribute__((__warning__("vsprintf() is dangerous, use vsnprintf()")))
|
||||||
|
#endif
|
||||||
int vsprintf(char* __restrict s, const char* __restrict format, __gnuc_va_list ap)
|
int vsprintf(char* __restrict s, const char* __restrict format, __gnuc_va_list ap)
|
||||||
__attribute__((__format__ (printf, 2, 0)));
|
__attribute__((__format__ (printf, 2, 0)));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue