mailing list of musl libc
 help / color / mirror / code / Atom feed
53e514ccaa4af9810aeafd185e77faec25905247 blob 1079 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
#include <stdio.h>
#include <wchar.h>
#include "atomic.h"
#include "libc.h"
#include "stdio_impl.h"

char *__fgets_chk(char *s, size_t size, int n, FILE *f)
{
	if ((size_t)n > size) a_crash();
	return fgets(s, n, f);
}

wchar_t *__fgetws_chk(wchar_t *s, size_t size, int n, FILE *f)
{
	if ((size_t)n > size) a_crash();
	return fgetws(s, n, f);
}

size_t __fread_chk(void *restrict destv, size_t destvlen, size_t size, size_t nmemb, FILE *restrict f)
{
	if (size != 0 && (size * nmemb) / size != nmemb) a_crash();
	if (size * nmemb > destvlen) a_crash();
	return fread(destv, size, nmemb, f);
}

char *__gets_chk(char *buf, size_t size)
{
	char *ret = buf;
	int c;
	FLOCK(stdin);
	if (!size) return NULL;
	for(;size;buf++,size--) {
		c = getc(stdin);
		if ((c == EOF && feof(stdin)) || c == '\n') {
			*buf = 0;
			FUNLOCK(stdin);
			return ret;
		}
		if (c == EOF) {
			FUNLOCK(stdin);
			return NULL;
		}
		*buf = c;
	}
	a_crash();
}

weak_alias(__fgets_chk, __fgets_unlocked_chk);
weak_alias(__fgetws_chk, __fgetws_unlocked_chk);
weak_alias(__fread_chk, __fread_unlocked_chk);
debug log:

solving 53e514c ...
found 53e514c in https://inbox.vuxu.org/musl/1434509291-28997-1-git-send-email-josiahw@gmail.com/

applying [1/1] https://inbox.vuxu.org/musl/1434509291-28997-1-git-send-email-josiahw@gmail.com/
diff --git a/src/compat/stdio_chk.c b/src/compat/stdio_chk.c
new file mode 100644
index 0000000..53e514c

Checking patch src/compat/stdio_chk.c...
Applied patch src/compat/stdio_chk.c cleanly.

index at:
100644 53e514ccaa4af9810aeafd185e77faec25905247	src/compat/stdio_chk.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).