]> granicus.if.org Git - file/commitdiff
PR/283: Tomas Siegl: Avoid SEGV on oomem.
authorChristos Zoulas <christos@zoulas.com>
Tue, 17 Sep 2013 15:51:22 +0000 (15:51 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 17 Sep 2013 15:51:22 +0000 (15:51 +0000)
src/ascmagic.c
src/encoding.c

index 9f1456a71c2b2818867a3f48ed311f4cc1956dec..7455a2e93d68241e8c6ba195233852dd577d815a 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.85 2012/08/09 16:33:15 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.86 2013/06/08 14:13:12 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -72,7 +72,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
        int text)
 {
        unichar *ubuf = NULL;
-       size_t ulen;
+       size_t ulen = 0;
        int rv = 1;
 
        const char *code = NULL;
index ca55720b0f3c174a62c6a3d3a7e43333f537f9be..77775ba8d3d5ddc061325b89daf6cbfcdc447aff 100644 (file)
@@ -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;
        }