diff options
author | Christos Zoulas <christos@zoulas.com> | 2013-09-17 15:51:22 +0000 |
---|---|---|
committer | Christos Zoulas <christos@zoulas.com> | 2013-09-17 15:51:22 +0000 |
commit | 6a035d38e7921205b39c16d2a872000ab711359c (patch) | |
tree | 74f19ebe9227deead1813d79187d0b4e6e92c79c /src/encoding.c | |
parent | 3cf59c337b30916e1d3583c46483c527c467cc6f (diff) | |
download | file-git-6a035d38e7921205b39c16d2a872000ab711359c.tar.gz |
PR/283: Tomas Siegl: Avoid SEGV on oomem.
Diffstat (limited to 'src/encoding.c')
-rw-r--r-- | src/encoding.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/encoding.c b/src/encoding.c index ca55720b..77775ba8 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: encoding.c,v 1.6 2011/12/08 12:38:24 rrt Exp $") +FILE_RCSID("@(#)$File: encoding.c,v 1.7 2012/01/24 19:02:02 christos Exp $") #endif /* lint */ #include "magic.h" @@ -72,13 +72,16 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni unsigned char *nbuf = NULL; *type = "text"; - mlen = (nbytes + 1) * sizeof(nbuf[0]); - if ((nbuf = CAST(unsigned char *, calloc((size_t)1, mlen))) == NULL) { + *ulen = 0; + *code = *code_mime = "unknown"; + + mlen = (nbytes + 1) * sizeof((*ubuf)[0]); + if ((*ubuf = CAST(unichar *, calloc((size_t)1, mlen))) == NULL) { file_oomem(ms, mlen); goto done; } - mlen = (nbytes + 1) * sizeof((*ubuf)[0]); - if ((*ubuf = CAST(unichar *, calloc((size_t)1, mlen))) == NULL) { + mlen = (nbytes + 1) * sizeof(nbuf[0]); + if ((nbuf = CAST(unsigned char *, calloc((size_t)1, mlen))) == NULL) { file_oomem(ms, mlen); goto done; } |