diff options
author | Scarlett <scarlett@xavin.net> | 2015-01-15 10:38:11 +0000 |
---|---|---|
committer | Tatsuya Kinoshita <tats@debian.org> | 2015-01-15 10:38:11 +0000 |
commit | cbec7032ee36346649fc5ebecc4b1c01f01178f1 (patch) | |
tree | 69907176f0aed9cef693dbbfd0398fa561c4a4cc /main.c | |
parent | Merge branch 'bug/printf' (diff) | |
download | w3m-cbec7032ee36346649fc5ebecc4b1c01f01178f1.tar.gz w3m-cbec7032ee36346649fc5ebecc4b1c01f01178f1.zip |
Add overflow detection
Origin: http://marc.info/?l=openbsd-ports&m=142090828929750&w=2
* main.c: Call exit(1) when out of memory to avoid dereferencing null
pointers when gc's malloc fails.
* alloc.h: Replacements for w3m's allocation macros which add
overflow detection and concentrate the macros in one file.
* indep.h, libwc/charset.c, libwc/status.c, matrix.c: Use the
overflow-detecting allocation macros from alloc.h.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -383,6 +383,13 @@ make_optional_header_string(char *s) return hs; } +static void * +die_oom(size_t bytes) +{ + fprintf(stderr, "Out of memory: %zu bytes unavailable!\n", bytes); + exit(1); +} + int main(int argc, char **argv, char **envp) { @@ -412,6 +419,7 @@ main(int argc, char **argv, char **envp) char **getimage_args = NULL; #endif /* defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) */ GC_INIT(); + GC_set_oom_fn(die_oom); #if defined(ENABLE_NLS) || (defined(USE_M17N) && defined(HAVE_LANGINFO_CODESET)) setlocale(LC_ALL, ""); #endif |