Browse code

bb#11296 - various fixes to pdf string base64 string conversion

Conflicts:
libclamav/str.h

Kevin Lin authored on 2015/04/15 04:53:17
Showing 4 changed files
... ...
@@ -115,7 +115,13 @@ char *cl_base64_encode(void *data, size_t len)
115 115
     size_t elen;
116 116
 
117 117
     b64 = BIO_new(BIO_f_base64());
118
+    if (!(b64))
119
+        return NULL;
118 120
     bio = BIO_new(BIO_s_mem());
121
+    if (!(bio)) {
122
+        BIO_free(b64);
123
+        return NULL;
124
+    }
119 125
 
120 126
     bio = BIO_push(b64, bio);
121 127
     BIO_write(bio, data, len);
... ...
@@ -59,6 +59,7 @@
59 59
 #include "arc4.h"
60 60
 #include "rijndael.h"
61 61
 #include "textnorm.h"
62
+#include "conv.h"
62 63
 #include "json_api.h"
63 64
 
64 65
 #ifdef	CL_DEBUG
... ...
@@ -3557,10 +3558,12 @@ static void pdf_export_json(struct pdf_struct *pdf)
3557 3557
         if (pdf->stats.author->meta.success && cli_isutf8(pdf->stats.author->data, pdf->stats.author->meta.length)) {
3558 3558
             cli_jsonstr(pdfobj, "Author", pdf->stats.author->data);
3559 3559
         } else if (pdf->stats.author->data && pdf->stats.author->meta.length) {
3560
-            char *b64 = (char *)cl_base64_encode(pdf->stats.author->data, pdf->stats.author->meta.length);
3560
+            char *b64 = cl_base64_encode(pdf->stats.author->data, pdf->stats.author->meta.length);
3561 3561
             cli_jsonstr(pdfobj, "Author", b64);
3562 3562
             cli_jsonbool(pdfobj, "Author_base64", 1);
3563 3563
             free(b64);
3564
+        } else {
3565
+            cli_jsonstr(pdfobj, "Author", "");
3564 3566
         }
3565 3567
     }
3566 3568
     if (pdf->stats.creator) {
... ...
@@ -3577,10 +3580,12 @@ static void pdf_export_json(struct pdf_struct *pdf)
3577 3577
         if (pdf->stats.creator->meta.success && cli_isutf8(pdf->stats.creator->data, pdf->stats.creator->meta.length)) {
3578 3578
             cli_jsonstr(pdfobj, "Creator", pdf->stats.creator->data);
3579 3579
         } else if (pdf->stats.creator->data && pdf->stats.creator->meta.length) {
3580
-            char *b64 = (char *)cl_base64_encode(pdf->stats.creator->data, pdf->stats.creator->meta.length);
3580
+            char *b64 = cl_base64_encode(pdf->stats.creator->data, pdf->stats.creator->meta.length);
3581 3581
             cli_jsonstr(pdfobj, "Creator", b64);
3582 3582
             cli_jsonbool(pdfobj, "Creator_base64", 1);
3583 3583
             free(b64);
3584
+        } else {
3585
+            cli_jsonstr(pdfobj, "Creator", "");
3584 3586
         }
3585 3587
     }
3586 3588
     if (pdf->stats.producer) {
... ...
@@ -3597,10 +3602,12 @@ static void pdf_export_json(struct pdf_struct *pdf)
3597 3597
         if (pdf->stats.producer->meta.success && cli_isutf8(pdf->stats.producer->data, pdf->stats.producer->meta.length)) {
3598 3598
             cli_jsonstr(pdfobj, "Producer", pdf->stats.producer->data);
3599 3599
         } else if (pdf->stats.producer->data && pdf->stats.producer->meta.length) {
3600
-            char *b64 = (char *)cl_base64_encode(pdf->stats.producer->data, pdf->stats.producer->meta.length);
3600
+            char *b64 = cl_base64_encode(pdf->stats.producer->data, pdf->stats.producer->meta.length);
3601 3601
             cli_jsonstr(pdfobj, "Producer", b64);
3602 3602
             cli_jsonbool(pdfobj, "Producer_base64", 1);
3603 3603
             free(b64);
3604
+        } else {
3605
+            cli_jsonstr(pdfobj, "Producer", "");
3604 3606
         }
3605 3607
     }
3606 3608
     if (pdf->stats.modificationdate) {
... ...
@@ -3617,10 +3624,12 @@ static void pdf_export_json(struct pdf_struct *pdf)
3617 3617
         if (pdf->stats.modificationdate->meta.success && cli_isutf8(pdf->stats.modificationdate->data, pdf->stats.modificationdate->meta.length)) {
3618 3618
             cli_jsonstr(pdfobj, "ModificationDate", pdf->stats.modificationdate->data);
3619 3619
         } else if (pdf->stats.modificationdate->data && pdf->stats.modificationdate->meta.length) {
3620
-            char *b64 = (char *)cl_base64_encode(pdf->stats.modificationdate->data, pdf->stats.modificationdate->meta.length);
3620
+            char *b64 = cl_base64_encode(pdf->stats.modificationdate->data, pdf->stats.modificationdate->meta.length);
3621 3621
             cli_jsonstr(pdfobj, "ModificationDate", b64);
3622 3622
             cli_jsonbool(pdfobj, "ModificationDate_base64", 1);
3623 3623
             free(b64);
3624
+        } else {
3625
+            cli_jsonstr(pdfobj, "ModificationDate", "");
3624 3626
         }
3625 3627
     }
3626 3628
     if (pdf->stats.creationdate) {
... ...
@@ -3637,10 +3646,12 @@ static void pdf_export_json(struct pdf_struct *pdf)
3637 3637
         if (pdf->stats.creationdate->meta.success && cli_isutf8(pdf->stats.creationdate->data, pdf->stats.creationdate->meta.length)) {
3638 3638
             cli_jsonstr(pdfobj, "CreationDate", pdf->stats.creationdate->data);
3639 3639
         } else if (pdf->stats.creationdate->data && pdf->stats.creationdate->meta.length) {
3640
-            char *b64 = (char *)cl_base64_encode(pdf->stats.creationdate->data, pdf->stats.creationdate->meta.length);
3640
+            char *b64 = cl_base64_encode(pdf->stats.creationdate->data, pdf->stats.creationdate->meta.length);
3641 3641
             cli_jsonstr(pdfobj, "CreationDate", b64);
3642 3642
             cli_jsonbool(pdfobj, "CreationDate_base64", 1);
3643 3643
             free(b64);
3644
+        } else {
3645
+            cli_jsonstr(pdfobj, "CreationDate", "");
3644 3646
         }
3645 3647
     }
3646 3648
     if (pdf->stats.title) {
... ...
@@ -3657,10 +3668,12 @@ static void pdf_export_json(struct pdf_struct *pdf)
3657 3657
         if (pdf->stats.title->meta.success && cli_isutf8(pdf->stats.title->data, pdf->stats.title->meta.length)) {
3658 3658
             cli_jsonstr(pdfobj, "Title", pdf->stats.title->data);
3659 3659
         } else if (pdf->stats.title->data && pdf->stats.title->meta.length) {
3660
-            char *b64 = (char *)cl_base64_encode(pdf->stats.title->data, pdf->stats.title->meta.length);
3660
+            char *b64 = cl_base64_encode(pdf->stats.title->data, pdf->stats.title->meta.length);
3661 3661
             cli_jsonstr(pdfobj, "Title", b64);
3662 3662
             cli_jsonbool(pdfobj, "Title_base64", 1);
3663 3663
             free(b64);
3664
+        } else {
3665
+            cli_jsonstr(pdfobj, "Title", "");
3664 3666
         }
3665 3667
     }
3666 3668
     if (pdf->stats.subject) {
... ...
@@ -3677,10 +3690,12 @@ static void pdf_export_json(struct pdf_struct *pdf)
3677 3677
         if (pdf->stats.subject->meta.success && cli_isutf8(pdf->stats.subject->data, pdf->stats.subject->meta.length)) {
3678 3678
             cli_jsonstr(pdfobj, "Subject", pdf->stats.subject->data);
3679 3679
         } else if (pdf->stats.subject->data && pdf->stats.subject->meta.length) {
3680
-            char *b64 = (char *)cl_base64_encode(pdf->stats.subject->data, pdf->stats.subject->meta.length);
3680
+            char *b64 = cl_base64_encode(pdf->stats.subject->data, pdf->stats.subject->meta.length);
3681 3681
             cli_jsonstr(pdfobj, "Subject", b64);
3682 3682
             cli_jsonbool(pdfobj, "Subject_base64", 1);
3683 3683
             free(b64);
3684
+        } else {
3685
+            cli_jsonstr(pdfobj, "Subject", "");
3684 3686
         }
3685 3687
     }
3686 3688
     if (pdf->stats.keywords) {
... ...
@@ -3697,10 +3712,12 @@ static void pdf_export_json(struct pdf_struct *pdf)
3697 3697
         if (pdf->stats.keywords->meta.success && cli_isutf8(pdf->stats.keywords->data, pdf->stats.keywords->meta.length)) {
3698 3698
             cli_jsonstr(pdfobj, "Keywords", pdf->stats.keywords->data);
3699 3699
         } else if (pdf->stats.keywords->data && pdf->stats.keywords->meta.length) {
3700
-            char *b64 = (char *)cl_base64_encode(pdf->stats.keywords->data, pdf->stats.keywords->meta.length);
3700
+            char *b64 = cl_base64_encode(pdf->stats.keywords->data, pdf->stats.keywords->meta.length);
3701 3701
             cli_jsonstr(pdfobj, "Keywords", b64);
3702 3702
             cli_jsonbool(pdfobj, "Keywords_base64", 1);
3703 3703
             free(b64);
3704
+        } else {
3705
+            cli_jsonbool(pdfobj, "Keywords", "");
3704 3706
         }
3705 3707
     }
3706 3708
     if (pdf->stats.ninvalidobjs)
... ...
@@ -667,7 +667,7 @@ char *cli_utf16_to_utf8(const char *utf16, size_t length, utf16_type type)
667 667
     return s2;
668 668
 }
669 669
 
670
-int cli_isutf8(const unsigned char *buf, unsigned int len)
670
+int cli_isutf8(const char *buf, unsigned int len)
671 671
 {
672 672
 	unsigned int i, j;
673 673
 
... ...
@@ -58,5 +58,5 @@ typedef enum {
58 58
 } utf16_type;
59 59
 char *cli_utf16_to_utf8(const char *utf16, size_t length, utf16_type type);
60 60
 
61
-int cli_isutf8(const unsigned char *buf, unsigned int len);
61
+int cli_isutf8(const char *buf, unsigned int len);
62 62
 #endif