summaryrefslogtreecommitdiff
path: root/src/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio')
-rw-r--r--src/stdio/fgetpos.c1
-rw-r--r--src/stdio/fgets.c1
-rw-r--r--src/stdio/fopen.c2
-rw-r--r--src/stdio/fopen_s.c4
-rw-r--r--src/stdio/fprintf.c2
-rw-r--r--src/stdio/fprintf_s.c2
-rw-r--r--src/stdio/fputs.c3
-rw-r--r--src/stdio/fread.c1
-rw-r--r--src/stdio/freopen.c3
-rw-r--r--src/stdio/fscanf.c2
-rw-r--r--src/stdio/fscanf_s.c2
-rw-r--r--src/stdio/fsetpos.c2
-rw-r--r--src/stdio/fwrite.c2
-rw-r--r--src/stdio/rename.c2
-rw-r--r--src/stdio/setbuf.c1
-rw-r--r--src/stdio/setvbuf.c1
-rw-r--r--src/stdio/snprintf.c2
-rw-r--r--src/stdio/snprintf_s.c2
-rw-r--r--src/stdio/sprintf.c1
-rw-r--r--src/stdio/sprintf_s.c2
-rw-r--r--src/stdio/sscanf.c2
-rw-r--r--src/stdio/sscanf_s.c2
-rw-r--r--src/stdio/vfprintf.c4
-rw-r--r--src/stdio/vfprintf_s.c3
-rw-r--r--src/stdio/vfscanf.c3
-rw-r--r--src/stdio/vfscanf_s.c3
-rw-r--r--src/stdio/vsnprintf.c3
-rw-r--r--src/stdio/vsnprintf_s.c3
-rw-r--r--src/stdio/vsprintf.c1
-rw-r--r--src/stdio/vsprintf_s.c2
-rw-r--r--src/stdio/vsscanf.c2
-rw-r--r--src/stdio/vsscanf_s.c3
32 files changed, 68 insertions, 1 deletions
diff --git a/src/stdio/fgetpos.c b/src/stdio/fgetpos.c
index 65b35cf7..8e6d201e 100644
--- a/src/stdio/fgetpos.c
+++ b/src/stdio/fgetpos.c
@@ -6,6 +6,7 @@
int fgetpos(FILE * restrict stream, fpos_t * restrict pos)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), pos, sizeof(*pos));
flockfile(stream);
*pos = stream->pos;
diff --git a/src/stdio/fgets.c b/src/stdio/fgets.c
index 195e724a..68ca7750 100644
--- a/src/stdio/fgets.c
+++ b/src/stdio/fgets.c
@@ -7,6 +7,7 @@ char * fgets(char * restrict s, int n, FILE * restrict stream)
{
int i = 0;
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, n, stream, sizeof(*stream));
if (feof(stream)) {
return NULL;
diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c
index e2ff7efc..4c9eabd7 100644
--- a/src/stdio/fopen.c
+++ b/src/stdio/fopen.c
@@ -1,6 +1,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "_stdio.h"
/** open a file stream **/
@@ -11,6 +12,7 @@ FILE * fopen(const char * restrict filename, const char * restrict mode)
size_t i;
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(filename, strlen(filename), mode, strlen(mode));
for (i = 0; i < FOPEN_MAX; i++) {
if (__stdio.FILES[i].bmode == 0) {
diff --git a/src/stdio/fopen_s.c b/src/stdio/fopen_s.c
index 411f6bbf..e74b7abd 100644
--- a/src/stdio/fopen_s.c
+++ b/src/stdio/fopen_s.c
@@ -1,7 +1,7 @@
#include <stdio.h>
-#include "_stdio.h"
#include <string.h>
#include <stdlib.h>
+#include "_stdio.h"
/** open a file stream **/
errno_t fopen_s(FILE * restrict * restrict streamptr,
@@ -9,6 +9,8 @@ errno_t fopen_s(FILE * restrict * restrict streamptr,
const char * restrict mode)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(streamptr, sizeof(*streamptr), filename, strlen(filename));
+ ASSERT_NOOVERLAP(streamptr, sizeof(*streamptr), mode, strlen(mode));
(void)streamptr; (void)filename; (void)mode;
return 0;
}
diff --git a/src/stdio/fprintf.c b/src/stdio/fprintf.c
index 72bca8c4..f7a0bc9c 100644
--- a/src/stdio/fprintf.c
+++ b/src/stdio/fprintf.c
@@ -1,5 +1,6 @@
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
/** write formatted output to a file stream **/
@@ -11,6 +12,7 @@ int fprintf(FILE * restrict stream, const char * restrict format, ...)
struct io_options opt = {0};
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), format, strlen(format));
opt.fnname = "fprintf";
opt.stream = stream;
diff --git a/src/stdio/fprintf_s.c b/src/stdio/fprintf_s.c
index 2e5ed670..83843f78 100644
--- a/src/stdio/fprintf_s.c
+++ b/src/stdio/fprintf_s.c
@@ -1,11 +1,13 @@
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
/** write formatted output to a file stream **/
int fprintf_s(FILE * restrict stream, const char * restrict format, ...)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), format, strlen(format));
int retval;
va_list ap;
va_start(ap, format);
diff --git a/src/stdio/fputs.c b/src/stdio/fputs.c
index a82338d1..c4d32dec 100644
--- a/src/stdio/fputs.c
+++ b/src/stdio/fputs.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
/** write a string to a file stream **/
@@ -6,6 +7,8 @@
int fputs(const char * restrict s, FILE * restrict stream)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, strlen(s), stream, sizeof(*stream));
+
flockfile(stream);
while (*s) {
if (fputc(*s++, stream) == EOF) {
diff --git a/src/stdio/fread.c b/src/stdio/fread.c
index 5b7f38b4..7ddf358f 100644
--- a/src/stdio/fread.c
+++ b/src/stdio/fread.c
@@ -9,6 +9,7 @@ size_t fread(void * restrict ptr, size_t size, size_t nmemb, FILE * restrict str
size_t n = 0;
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(ptr, size * nmemb, stream, sizeof(*stream));
flockfile(stream);
while (nmemb) {
diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c
index b40eb439..d361023a 100644
--- a/src/stdio/freopen.c
+++ b/src/stdio/freopen.c
@@ -55,6 +55,9 @@ FILE * freopen(const char * restrict filename, const char * restrict mode, FILE
int fd = -1;
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(filename, strlen(filename), mode, strlen(mode));
+ ASSERT_NOOVERLAP(filename, strlen(filename), stream, sizeof(*stream));
+ ASSERT_NOOVERLAP(mode, strlen(mode), stream, sizeof(*stream));
for (i = 0; i < sizeof(modemap) / sizeof(modemap[0]); i++) {
if (!strcmp(modemap[i].smode, mode)) {
diff --git a/src/stdio/fscanf.c b/src/stdio/fscanf.c
index 98dbeed1..2299fd11 100644
--- a/src/stdio/fscanf.c
+++ b/src/stdio/fscanf.c
@@ -1,5 +1,6 @@
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
/** read formatted input from a file stream **/
@@ -11,6 +12,7 @@ int fscanf(FILE * restrict stream, const char * restrict format, ...)
struct io_options opt = {0};
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), format, strlen(format));
opt.fnname = "fscanf";
opt.stream = stream;
diff --git a/src/stdio/fscanf_s.c b/src/stdio/fscanf_s.c
index 4d01ba5e..310ca5da 100644
--- a/src/stdio/fscanf_s.c
+++ b/src/stdio/fscanf_s.c
@@ -1,11 +1,13 @@
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
/** read formatted input from a file stream **/
int fscanf_s(FILE * restrict stream, const char * restrict format, ...)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), format, strlen(format));
va_list ap;
va_start(ap, format);
int ret = vfscanf_s(stream, format, ap);
diff --git a/src/stdio/fsetpos.c b/src/stdio/fsetpos.c
index ca6cb806..40545061 100644
--- a/src/stdio/fsetpos.c
+++ b/src/stdio/fsetpos.c
@@ -6,6 +6,8 @@
int fsetpos(FILE *stream, const fpos_t *pos)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), pos, sizeof(*pos));
+
(void)stream; (void)pos;
/* TODO */
return 1;
diff --git a/src/stdio/fwrite.c b/src/stdio/fwrite.c
index 52861b00..ab2e0f04 100644
--- a/src/stdio/fwrite.c
+++ b/src/stdio/fwrite.c
@@ -7,7 +7,9 @@ size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb, FILE * restr
{
unsigned char *buf = (unsigned char *)ptr;
size_t n = 0;
+
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(ptr, size * nmemb, stream, sizeof(*stream));
while (nmemb) {
size_t i;
diff --git a/src/stdio/rename.c b/src/stdio/rename.c
index 84d0df35..9a701a1d 100644
--- a/src/stdio/rename.c
+++ b/src/stdio/rename.c
@@ -1,5 +1,6 @@
#include <errno.h>
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
#include "_syscall.h"
@@ -8,6 +9,7 @@
int rename(const char *old, const char *new)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(old, strlen(old), new, strlen(new));
SYSCALL(rename, int, -1, old, new, 0, 0, 0, 0);
}
diff --git a/src/stdio/setbuf.c b/src/stdio/setbuf.c
index ddf38856..38072548 100644
--- a/src/stdio/setbuf.c
+++ b/src/stdio/setbuf.c
@@ -8,6 +8,7 @@ void setbuf(FILE * restrict stream, char * restrict buf)
SIGNAL_SAFE(0);
if (buf) {
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), buf, BUFSIZ);
setvbuf(stream, buf, _IOFBF, BUFSIZ);
} else {
setvbuf(stream, NULL, _IONBF, 0);
diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c
index a6f37fb0..b400b266 100644
--- a/src/stdio/setvbuf.c
+++ b/src/stdio/setvbuf.c
@@ -8,6 +8,7 @@
int setvbuf(FILE *stream, char *buf, int mode, size_t size)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), buf, size);
flockfile(stream);
diff --git a/src/stdio/snprintf.c b/src/stdio/snprintf.c
index 9bf6d17b..4ee9ec7f 100644
--- a/src/stdio/snprintf.c
+++ b/src/stdio/snprintf.c
@@ -1,10 +1,12 @@
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
int snprintf(char * restrict s, size_t n, const char * restrict format, ...)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, n, format, strlen(format));
struct io_options opt = {
.fnname = __func__,
diff --git a/src/stdio/snprintf_s.c b/src/stdio/snprintf_s.c
index aa7768f9..b3b8c0fc 100644
--- a/src/stdio/snprintf_s.c
+++ b/src/stdio/snprintf_s.c
@@ -1,9 +1,11 @@
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
int snprintf_s( char * restrict s, rsize_t n, const char * restrict format, ...)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, n, format, strlen(format));
(void)s; (void)n; (void)format;
return 0;
}
diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c
index 5b1ad29f..fcb1ddac 100644
--- a/src/stdio/sprintf.c
+++ b/src/stdio/sprintf.c
@@ -12,6 +12,7 @@ int sprintf(char * restrict s, const char * restrict format, ...)
struct io_options opt = {0};
SIGNAL_SAFE(0);
+ /* overlap can't be detected because the length of s is unknown */
opt.fnname = "sprintf";
opt.string = s;
diff --git a/src/stdio/sprintf_s.c b/src/stdio/sprintf_s.c
index 81613ecb..e640abf7 100644
--- a/src/stdio/sprintf_s.c
+++ b/src/stdio/sprintf_s.c
@@ -1,11 +1,13 @@
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
/** write formatted output to a string **/
int sprintf_s(char * restrict s, rsize_t n, const char * restrict format, ...)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, n, format, strlen(format));
(void)n;
diff --git a/src/stdio/sscanf.c b/src/stdio/sscanf.c
index 125a49f6..4fab8b61 100644
--- a/src/stdio/sscanf.c
+++ b/src/stdio/sscanf.c
@@ -1,5 +1,6 @@
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
/** read formatted input from a string **/
@@ -11,6 +12,7 @@ int sscanf(const char * restrict s, const char * restrict format, ...)
struct io_options opt = {0};
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, strlen(s), format, strlen(format));
opt.fnname = "sscanf";
opt.string = (char *)s;
diff --git a/src/stdio/sscanf_s.c b/src/stdio/sscanf_s.c
index 20249496..08bbd6e5 100644
--- a/src/stdio/sscanf_s.c
+++ b/src/stdio/sscanf_s.c
@@ -1,11 +1,13 @@
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
/** read formatted input from a string **/
int sscanf_s(const char * restrict s, const char * restrict format, ...)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, strlen(s), format, strlen(format));
va_list ap;
va_start(ap, format);
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 0e3f9557..91de900d 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -1,5 +1,6 @@
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
/** write formatted output to a file stream **/
@@ -8,7 +9,10 @@ int vfprintf(FILE * restrict stream, const char * restrict format, va_list arg)
{
int ret = 0;
struct io_options opt = {0};
+
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(stream), format, strlen(format));
+
opt.fnname = "vfprintf";
opt.stream = stream;
ret = __printf(&opt, format, arg);
diff --git a/src/stdio/vfprintf_s.c b/src/stdio/vfprintf_s.c
index 941b03c0..b11f27e8 100644
--- a/src/stdio/vfprintf_s.c
+++ b/src/stdio/vfprintf_s.c
@@ -1,11 +1,14 @@
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
/** write formatted output to a file stream **/
int vfprintf_s(FILE * restrict stream, const char * restrict format, va_list arg)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), format, strlen(format));
+
struct io_options opt = {
.fnname = __func__,
.stream = stream,
diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c
index 0df43d92..af0dc289 100644
--- a/src/stdio/vfscanf.c
+++ b/src/stdio/vfscanf.c
@@ -1,9 +1,12 @@
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), format, strlen(format));
+
struct io_options opt = {
.fnname = __func__,
.stream = stream,
diff --git a/src/stdio/vfscanf_s.c b/src/stdio/vfscanf_s.c
index ca7b84d1..7654abd3 100644
--- a/src/stdio/vfscanf_s.c
+++ b/src/stdio/vfscanf_s.c
@@ -1,9 +1,12 @@
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
int vfscanf_s(FILE * restrict stream, const char * restrict format, va_list arg)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(stream, sizeof(*stream), format, strlen(format));
+
(void)stream; (void)format; (void)arg;
return 0;
}
diff --git a/src/stdio/vsnprintf.c b/src/stdio/vsnprintf.c
index 3fa18cf4..87deb169 100644
--- a/src/stdio/vsnprintf.c
+++ b/src/stdio/vsnprintf.c
@@ -1,10 +1,13 @@
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
int vsnprintf(char * restrict s, size_t n, const char *format, va_list arg)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, n, format, strlen(format));
+
struct io_options opt = {
.fnname = __func__,
.string = s,
diff --git a/src/stdio/vsnprintf_s.c b/src/stdio/vsnprintf_s.c
index 3d094fe5..2f980931 100644
--- a/src/stdio/vsnprintf_s.c
+++ b/src/stdio/vsnprintf_s.c
@@ -1,9 +1,12 @@
#include <stdio.h>
+#include <string.h>
#include "_stdio.h"
int vsnprintf_s(char * restrict s, rsize_t n, const char * restrict format, va_list arg)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, n, format, strlen(format));
+
struct io_options opt = {
.fnname = __func__,
.string = s,
diff --git a/src/stdio/vsprintf.c b/src/stdio/vsprintf.c
index ef4d40a0..6edf9f2f 100644
--- a/src/stdio/vsprintf.c
+++ b/src/stdio/vsprintf.c
@@ -10,6 +10,7 @@ int vsprintf(char *s, const char *format, va_list arg)
struct io_options opt = {0};
SIGNAL_SAFE(0);
+ /* overlap can't be detected because the size of s is unknown */
opt.fnname = "fprintf";
opt.string = s;
diff --git a/src/stdio/vsprintf_s.c b/src/stdio/vsprintf_s.c
index 02a0899f..38500801 100644
--- a/src/stdio/vsprintf_s.c
+++ b/src/stdio/vsprintf_s.c
@@ -1,12 +1,14 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
+#include <string.h>
#include "_stdio.h"
/** write formatted output to a string **/
int vsprintf_s(char *s, rsize_t n, const char *format, va_list arg)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, n, format, strlen(format));
(void)n;
return vsnprintf(s, SIZE_MAX, format, arg);
}
diff --git a/src/stdio/vsscanf.c b/src/stdio/vsscanf.c
index b803e262..183d9f2d 100644
--- a/src/stdio/vsscanf.c
+++ b/src/stdio/vsscanf.c
@@ -1,10 +1,12 @@
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
int vsscanf(const char * restrict s, const char * restrict format, va_list arg)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, strlen(s), format, strlen(format));
struct io_options opt = {
.fnname = __func__,
diff --git a/src/stdio/vsscanf_s.c b/src/stdio/vsscanf_s.c
index 3e3ea62f..63ec80bf 100644
--- a/src/stdio/vsscanf_s.c
+++ b/src/stdio/vsscanf_s.c
@@ -1,9 +1,12 @@
#include <stdarg.h>
+#include <string.h>
#include "_stdio.h"
int vsscanf_s(const char * restrict s, const char * restrict format, va_list arg)
{
SIGNAL_SAFE(0);
+ ASSERT_NOOVERLAP(s, strlen(s), format, strlen(format));
+
(void)s; (void)format; (void)arg;
return 0;
}