Browse code

eliminated a large number of warnings, many of which had to do with mixing types. i switched some types to size_t and a couple to ptrdiff_t to make things more consistent, but there is a huge amount of work to be done to make types consistent. int, unsigned int, unsigned, off_t, and other types are ill-suited to storing buffer lengths or memory addresses.

Micah Snyder authored on 2017/08/17 06:31:45
Showing 9 changed files
... ...
@@ -213,7 +213,7 @@ static int mspack_fmap_seek(struct mspack_file *file, off_t offset, int mode)
213 213
 			cli_dbgmsg("%s() err %d\n", __func__, __LINE__);
214 214
 			return -1;
215 215
 		}
216
-		if (new_pos < 0 || new_pos > mspack_handle->fmap->len) {
216
+		if (new_pos < 0 || new_pos > (off_t)mspack_handle->fmap->len) {
217 217
 			cli_dbgmsg("%s() err %d\n", __func__, __LINE__);
218 218
 			return -1;
219 219
 		}
... ...
@@ -255,10 +255,12 @@ static off_t mspack_fmap_tell(struct mspack_file *file)
255 255
 
256 256
 static void mspack_fmap_message(struct mspack_file *file, const char *fmt, ...)
257 257
 {
258
+	UNUSEDPARAM(file);
258 259
 	cli_dbgmsg("%s() %s\n", __func__, fmt);
259 260
 }
260 261
 static void *mspack_fmap_alloc(struct mspack_system *self, size_t num)
261 262
 {
263
+	UNUSEDPARAM(self);
262 264
 	return malloc(num);
263 265
 }
264 266
 
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2015 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
2
+ *  Copyright (C) 2015, 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
3 3
  *  Copyright (C) 2007-2008 Sourcefire, Inc.
4 4
  *
5 5
  *  Authors: Michal 'GiM' Spadlinski
... ...
@@ -783,7 +783,7 @@ uint32_t lzma_upack_esi_54(struct lzmastate *p, uint32_t old_eax, uint32_t *old_
783 783
 }
784 784
 
785 785
 
786
-int unmew11(char *src, int off, int ssize, int dsize, uint32_t base, uint32_t vadd, int uselzma, int filedesc)
786
+int unmew11(char *src, uint32_t off, uint32_t ssize, uint32_t dsize, uint32_t base, uint32_t vadd, int uselzma, int filedesc)
787 787
 {
788 788
 	uint32_t entry_point, newedi, loc_ds=dsize, loc_ss=ssize;
789 789
 	char *source = src + dsize + off;
... ...
@@ -863,7 +863,7 @@ int unmew11(char *src, int off, int ssize, int dsize, uint32_t base, uint32_t va
863 863
              * or, in other words, exceed the specified size of destination
864 864
              */
865 865
             if (section[i].raw + section[i].rsz > dsize) {
866
-                cli_dbgmsg("MEW: Section %i [%d, %d] exceeds destination size %d\n",
866
+                cli_dbgmsg("MEW: Section %i [%d, %d] exceeds destination size %u\n",
867 867
                            i, section[i].raw, section[i].raw+section[i].rsz, dsize);
868 868
                 free(section);
869 869
                 return -1;
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2015 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
2
+ *  Copyright (C) 2015, 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
3 3
  *  Copyright (C) 2007-2008 Sourcefire, Inc.
4 4
  *
5 5
  *  Authors: Michal 'GiM' Spadlinski
... ...
@@ -38,6 +38,6 @@ int mew_lzma(char *, const char *, uint32_t, uint32_t, uint32_t);
38 38
 uint32_t lzma_upack_esi_00(struct lzmastate *, char *, char *, uint32_t);
39 39
 uint32_t lzma_upack_esi_50(struct lzmastate *, uint32_t, uint32_t, char **, char *, uint32_t *, char *, uint32_t);
40 40
 uint32_t lzma_upack_esi_54(struct lzmastate *, uint32_t, uint32_t *, char **, uint32_t *, char *, uint32_t);
41
-int unmew11(char *, int, int, int, uint32_t, uint32_t, int, int);
41
+int unmew11(char *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, int, int);
42 42
 
43 43
 #endif
... ...
@@ -559,67 +559,66 @@ struct unaligned_ptr {
559 559
 #endif
560 560
 
561 561
 #if WORDS_BIGENDIAN == 0
562
-
563
-/* Little endian */
564
-#define le16_to_host(v)	(v)
565
-#define le32_to_host(v)	(v)
566
-#define le64_to_host(v)	(v)
567
-#define	be16_to_host(v)	cbswap16(v)
568
-#define	be32_to_host(v)	cbswap32(v)
569
-#define be64_to_host(v) cbswap64(v)
570
-#define cli_readint64(buff) (((const union unaligned_64 *)(buff))->una_s64)
571
-#define cli_readint32(buff) (((const union unaligned_32 *)(buff))->una_s32)
572
-#define cli_readint16(buff) (((const union unaligned_16 *)(buff))->una_s16)
573
-#define cli_writeint32(offset, value) (((union unaligned_32 *)(offset))->una_u32=(uint32_t)(value))
562
+    /* Little endian */
563
+    #define le16_to_host(v)	(v)
564
+    #define le32_to_host(v)	(v)
565
+    #define le64_to_host(v)	(v)
566
+    #define	be16_to_host(v)	cbswap16(v)
567
+    #define	be32_to_host(v)	cbswap32(v)
568
+    #define be64_to_host(v) cbswap64(v)
569
+    #define cli_readint64(buff) (((const union unaligned_64 *)(buff))->una_s64)
570
+    #define cli_readint32(buff) (((const union unaligned_32 *)(buff))->una_s32)
571
+    #define cli_readint16(buff) (((const union unaligned_16 *)(buff))->una_s16)
572
+    #define cli_writeint32(offset, value) (((union unaligned_32 *)(offset))->una_u32=(uint32_t)(value))
574 573
 #else
575
-/* Big endian */
576
-#define	le16_to_host(v)	cbswap16(v)
577
-#define	le32_to_host(v)	cbswap32(v)
578
-#define le64_to_host(v) cbswap64(v)
579
-#define be16_to_host(v)	(v)
580
-#define be32_to_host(v)	(v)
581
-#define be64_to_host(v)	(v)
582
-
583
-static inline int32_t cli_readint64(const void *buff)
584
-{
585
-	int64_t ret;
586
-    ret = ((const char *)buff)[0] & 0xff;
587
-    ret |= (((const char *)buff)[1] & 0xff) << 8;
588
-    ret |= (((const char *)buff)[2] & 0xff) << 16;
589
-    ret |= (((const char *)buff)[3] & 0xff) << 24;
590
-
591
-    ret |= (((const char *)buff)[4] & 0xff) << 32;
592
-    ret |= (((const char *)buff)[5] & 0xff) << 40;
593
-    ret |= (((const char *)buff)[6] & 0xff) << 48;
594
-    ret |= (((const char *)buff)[7] & 0xff) << 56;
595
-    return ret;
596
-}
597
-
598
-static inline int32_t cli_readint32(const void *buff)
599
-{
600
-	int32_t ret;
601
-    ret = ((const char *)buff)[0] & 0xff;
602
-    ret |= (((const char *)buff)[1] & 0xff) << 8;
603
-    ret |= (((const char *)buff)[2] & 0xff) << 16;
604
-    ret |= (((const char *)buff)[3] & 0xff) << 24;
605
-    return ret;
606
-}
607
-
608
-static inline int16_t cli_readint16(const void *buff)
609
-{
610
-	int16_t ret;
611
-    ret = ((const char *)buff)[0] & 0xff;
612
-    ret |= (((const char *)buff)[1] & 0xff) << 8;
613
-    return ret;
614
-}
615
-
616
-static inline void cli_writeint32(void *offset, uint32_t value)
617
-{
618
-    ((char *)offset)[0] = value & 0xff;
619
-    ((char *)offset)[1] = (value & 0xff00) >> 8;
620
-    ((char *)offset)[2] = (value & 0xff0000) >> 16;
621
-    ((char *)offset)[3] = (value & 0xff000000) >> 24;
622
-}
574
+    /* Big endian */
575
+    #define	le16_to_host(v)	cbswap16(v)
576
+    #define	le32_to_host(v)	cbswap32(v)
577
+    #define le64_to_host(v) cbswap64(v)
578
+    #define be16_to_host(v)	(v)
579
+    #define be32_to_host(v)	(v)
580
+    #define be64_to_host(v)	(v)
581
+
582
+    static inline int32_t cli_readint64(const void *buff)
583
+    {
584
+        int64_t ret;
585
+        ret = ((const char *)buff)[0] & 0xff;
586
+        ret |= (((const char *)buff)[1] & 0xff) << 8;
587
+        ret |= (((const char *)buff)[2] & 0xff) << 16;
588
+        ret |= (((const char *)buff)[3] & 0xff) << 24;
589
+
590
+        ret |= (((const char *)buff)[4] & 0xff) << 32;
591
+        ret |= (((const char *)buff)[5] & 0xff) << 40;
592
+        ret |= (((const char *)buff)[6] & 0xff) << 48;
593
+        ret |= (((const char *)buff)[7] & 0xff) << 56;
594
+        return ret;
595
+    }
596
+
597
+    static inline int32_t cli_readint32(const void *buff)
598
+    {
599
+        int32_t ret;
600
+        ret = ((const char *)buff)[0] & 0xff;
601
+        ret |= (((const char *)buff)[1] & 0xff) << 8;
602
+        ret |= (((const char *)buff)[2] & 0xff) << 16;
603
+        ret |= (((const char *)buff)[3] & 0xff) << 24;
604
+        return ret;
605
+    }
606
+
607
+    static inline int16_t cli_readint16(const void *buff)
608
+    {
609
+        int16_t ret;
610
+        ret = ((const char *)buff)[0] & 0xff;
611
+        ret |= (((const char *)buff)[1] & 0xff) << 8;
612
+        return ret;
613
+    }
614
+
615
+    static inline void cli_writeint32(void *offset, uint32_t value)
616
+    {
617
+        ((char *)offset)[0] = value & 0xff;
618
+        ((char *)offset)[1] = (value & 0xff00) >> 8;
619
+        ((char *)offset)[2] = (value & 0xff0000) >> 16;
620
+        ((char *)offset)[3] = (value & 0xff000000) >> 24;
621
+    }
623 622
 #endif
624 623
 
625 624
 int cli_append_virus(cli_ctx *ctx, const char *virname);
... ...
@@ -146,14 +146,14 @@ static int xrefCheck(const char *xref, const char *eof)
146 146
 }
147 147
 
148 148
 /* define this to be noisy about things that we can't parse properly */
149
-/*#define NOISY*/
149
+#define NOISY
150 150
 
151 151
 #ifdef NOISY
152 152
 #define noisy_msg(pdf, ...) cli_infomsg(pdf->ctx, __VA_ARGS__)
153
-#define noisy_warnmsg cli_warnmsg
153
+#define noisy_warnmsg(...) cli_warnmsg(__VA_ARGS__)
154 154
 #else
155
-#define noisy_msg (void)
156
-#define noisy_warnmsg (void)
155
+#define noisy_msg(pdf, ...)
156
+#define noisy_warnmsg(...)
157 157
 #endif
158 158
 
159 159
 static const char *findNextNonWSBack(const char *q, const char *start)
... ...
@@ -291,16 +291,16 @@ int pdf_findobj(struct pdf_struct *pdf)
291 291
     return 1;/* truncated */
292 292
 }
293 293
 
294
-static int filter_writen(struct pdf_struct *pdf, struct pdf_obj *obj, int fout, const char *buf, off_t len, off_t *sum)
294
+static size_t filter_writen(struct pdf_struct *pdf, struct pdf_obj *obj, int fout, const char *buf, size_t len, size_t *sum)
295 295
 {
296 296
     UNUSEDPARAM(obj);
297 297
 
298
-    if (cli_checklimits("pdf", pdf->ctx, *sum, 0, 0))
298
+    if (cli_checklimits("pdf", pdf->ctx, (unsigned long)*sum, 0, 0)) /* TODO: May truncate for large values on 64-bit platforms */
299 299
         return len; /* pretend it was a successful write to suppress CL_EWRITE */
300 300
 
301 301
     *sum += len;
302 302
 
303
-    return cli_writen(fout, buf, len);
303
+    return cli_writen(fout, buf, (unsigned int)len);
304 304
 }
305 305
 
306 306
 void pdfobj_flag(struct pdf_struct *pdf, struct pdf_obj *obj, enum pdf_flag flag)
... ...
@@ -533,23 +533,23 @@ static int run_pdf_hooks(struct pdf_struct *pdf, enum pdf_phase phase, int fd, i
533 533
 
534 534
 static void dbg_printhex(const char *msg, const char *hex, unsigned len);
535 535
 
536
-static void aes_decrypt(const unsigned char *in, off_t *length, unsigned char *q, char *key, unsigned key_n, int has_iv)
536
+static void aes_decrypt(const unsigned char *in, size_t *length, unsigned char *q, char *key, unsigned key_n, int has_iv)
537 537
 {
538 538
     unsigned long rk[RKLENGTH(256)];
539 539
     unsigned char iv[16];
540
-    unsigned len = *length;
540
+    size_t len = *length;
541 541
     unsigned char pad, i;
542 542
     int nrounds;
543 543
 
544
-    cli_dbgmsg("cli_pdf: aes_decrypt: key length: %d, data length: %d\n", key_n, (int)*length);
544
+    cli_dbgmsg("cli_pdf: aes_decrypt: key length: %d, data length: %zu\n", key_n, *length);
545 545
     if (key_n > 32) {
546 546
         cli_dbgmsg("cli_pdf: aes_decrypt: key length is %d!\n", key_n*8);
547 547
         return;
548 548
     }
549 549
 
550 550
     if (len < 32) {
551
-        cli_dbgmsg("cli_pdf: aes_decrypt: len is <32: %d\n", len);
552
-        noisy_warnmsg("cli_pdf: aes_decrypt: len is <32: %d\n", len);
551
+        cli_dbgmsg("cli_pdf: aes_decrypt: len is <32: %zu\n", len);
552
+        noisy_warnmsg("cli_pdf: aes_decrypt: len is <32: %zu\n", len);
553 553
         return;
554 554
     }
555 555
 
... ...
@@ -587,8 +587,8 @@ static void aes_decrypt(const unsigned char *in, off_t *length, unsigned char *q
587 587
         pad = q[-1];
588 588
 
589 589
         if (pad > 0x10) {
590
-            cli_dbgmsg("cli_pdf: aes_decrypt: bad pad: %x (extra len: %d)\n", pad, len-16);
591
-            noisy_warnmsg("cli_pdf: aes_decrypt: bad pad: %x (extra len: %d)\n", pad, len-16);
590
+            cli_dbgmsg("cli_pdf: aes_decrypt: bad pad: %x (extra len: %zu)\n", pad, len-16);
591
+            noisy_warnmsg("cli_pdf: aes_decrypt: bad pad: %x (extra len: %zu)\n", pad, len-16);
592 592
             *length -= len;
593 593
             return;
594 594
         }
... ...
@@ -609,11 +609,11 @@ static void aes_decrypt(const unsigned char *in, off_t *length, unsigned char *q
609 609
 
610 610
     *length -= len;
611 611
 
612
-    cli_dbgmsg("cli_pdf: aes_decrypt: length is %d\n", (int)*length);
612
+    cli_dbgmsg("cli_pdf: aes_decrypt: length is %zu\n", *length);
613 613
 }
614 614
 
615 615
 
616
-char *decrypt_any(struct pdf_struct *pdf, uint32_t id, const char *in, off_t *length, enum enc_method enc_method)
616
+char *decrypt_any(struct pdf_struct *pdf, uint32_t id, const char *in, size_t *length, enum enc_method enc_method)
617 617
 {
618 618
     unsigned char *key, *q, result[16];
619 619
     unsigned n;
... ...
@@ -662,7 +662,7 @@ char *decrypt_any(struct pdf_struct *pdf, uint32_t id, const char *in, off_t *le
662 662
         cli_dbgmsg("cli_pdf: enc is v2\n");
663 663
         memcpy(q, in, *length);
664 664
         arc4_init(&arc4, result, n);
665
-        arc4_apply(&arc4, q, *length);
665
+        arc4_apply(&arc4, q, (unsigned)*length); /* TODO: may truncate for very large lengths */
666 666
 
667 667
         noisy_msg(pdf, "decrypted ARC4 data\n");
668 668
 
... ...
@@ -818,7 +818,7 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
818 818
 {
819 819
     char fullname[NAME_MAX + 1];
820 820
     int fout;
821
-    off_t sum = 0;
821
+    ptrdiff_t sum = 0;
822 822
     int rc = CL_SUCCESS;
823 823
     int dump = 1;
824 824
 
... ...
@@ -883,10 +883,10 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
883 883
 
884 884
                 orig_length = length;
885 885
                 if (length > pdf->size || obj->start + p_stream + length > pdf->size) {
886
-                    cli_dbgmsg("cli_pdf: length out of file: %ld + %ld > %ld\n",
887
-                           p_stream, length, pdf->size);
888
-                    noisy_warnmsg("length out of file, truncated: %ld + %ld > %ld\n",
889
-                           p_stream, length, pdf->size);
886
+                    cli_dbgmsg("cli_pdf: length out of file: %lld + %lld > %lld\n",
887
+                           (long long)p_stream, (long long)length, (long long)pdf->size);
888
+                    noisy_warnmsg("length out of file, truncated: %lld + %lld > %lld\n",
889
+                           (long long)p_stream, (long long)length, (long long)pdf->size);
890 890
                     length = pdf->size - (obj->start + p_stream);
891 891
                 }
892 892
 
... ...
@@ -961,7 +961,7 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
961 961
                         cli_dbgmsg("cli_pdf: failed to locate DecodeParms dictionary start\n");
962 962
                 }
963 963
 
964
-                sum = pdf_decodestream(pdf, obj, dparams, start + p_stream, length, xref, fout, &rc);
964
+                sum = pdf_decodestream(pdf, obj, dparams, start + p_stream, (uint32_t)length, xref, fout, &rc);
965 965
                 if (dparams)
966 966
                     pdf_free_dict(dparams);
967 967
 
... ...
@@ -985,7 +985,7 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
985 985
 
986 986
             do {
987 987
                 char *js = NULL;
988
-                off_t js_len = 0;
988
+                size_t js_len = 0;
989 989
                 const char *q3;
990 990
 
991 991
                 q2 = cli_memstr(q, bytesleft, "/JavaScript", 11);
... ...
@@ -1005,8 +1005,7 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
1005 1005
                     js_len = strlen(js);
1006 1006
                     if (pdf->flags & (1 << DECRYPTABLE_PDF)) {
1007 1007
                         cli_dbgmsg("cli_pdf: encrypted string\n");
1008
-                        decrypted = decrypt_any(pdf, obj->id, js, &js_len,
1009
-                        pdf->enc_method_string);
1008
+                        decrypted = decrypt_any(pdf, obj->id, js, &js_len, pdf->enc_method_string);
1010 1009
 
1011 1010
                         if (decrypted) {
1012 1011
                             noisy_msg(pdf, "decrypted Javascript string from obj %u %u\n", obj->id>>8,obj->id&0xff);
... ...
@@ -1014,7 +1013,7 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
1014 1014
                         }
1015 1015
                     }
1016 1016
 
1017
-                    if (filter_writen(pdf, obj, fout, out, js_len, &sum) != js_len) {
1017
+                    if (filter_writen(pdf, obj, fout, out, js_len, (size_t*)&sum) != js_len) {
1018 1018
                         rc = CL_EWRITE;
1019 1019
                                 free(js);
1020 1020
                         break;
... ...
@@ -1039,7 +1038,7 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
1039 1039
 
1040 1040
                         if (q2 > q) {
1041 1041
                             q--;
1042
-                            filter_writen(pdf, obj, fout, q, q2 - q, &sum);
1042
+                            filter_writen(pdf, obj, fout, q, q2 - q, (size_t*)&sum);
1043 1043
                             q++;
1044 1044
                         }
1045 1045
                     }
... ...
@@ -1051,7 +1050,7 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
1051 1051
 
1052 1052
             if (bytesleft < 0)
1053 1053
                 rc = CL_EFORMAT;
1054
-            else if (filter_writen(pdf, obj, fout , pdf->map + obj->start, bytesleft,&sum) != bytesleft)
1054
+            else if (filter_writen(pdf, obj, fout , pdf->map + obj->start, bytesleft, (size_t*)&sum) != (size_t)bytesleft)
1055 1055
                 rc = CL_EWRITE;
1056 1056
         }
1057 1057
     } while (0);
... ...
@@ -1909,15 +1908,15 @@ static void check_user_password(struct pdf_struct *pdf, int R, const char *O,
1909 1909
         cl_sha256(U+32, 8, result2, NULL);
1910 1910
         dbg_printhex("Computed U", (const char *)result2, 32);
1911 1911
         if (!memcmp(result2, U, 32)) {
1912
-            off_t n;
1912
+            size_t UE_len;
1913 1913
 
1914 1914
             /* Algorithm 3.2a could be used to recover encryption key */
1915 1915
             password_empty = 1;
1916 1916
             cl_sha256(U+40, 8, result2, NULL);
1917
-            n = UE ? strlen(UE) : 0;
1918
-            if (n != 32) {
1919
-                cli_dbgmsg("cli_pdf: UE length is not 32: %d\n", (int)n);
1920
-                noisy_warnmsg("cli_pdf: UE length is not 32: %d\n", n);
1917
+            UE_len = UE ? strlen(UE) : 0;
1918
+            if (UE_len != 32) {
1919
+                cli_dbgmsg("cli_pdf: UE length is not 32: %zu\n", UE_len);
1920
+                noisy_warnmsg("cli_pdf: UE length is not 32: %zu\n", UE_len);
1921 1921
             } else {
1922 1922
                 pdf->keylen = 32;
1923 1923
                 pdf->key = cli_malloc(32);
... ...
@@ -1926,7 +1925,7 @@ static void check_user_password(struct pdf_struct *pdf, int R, const char *O,
1926 1926
                     return;
1927 1927
                 }
1928 1928
 
1929
-                aes_decrypt((const unsigned char *)UE, &n, (unsigned char *)(pdf->key), (char *)result2, 32, 0);
1929
+                aes_decrypt((const unsigned char *)UE, &UE_len, (unsigned char *)(pdf->key), (char *)result2, 32, 0);
1930 1930
                 dbg_printhex("cli_pdf: Candidate encryption key", pdf->key, pdf->keylen);
1931 1931
             }
1932 1932
         }
... ...
@@ -2206,7 +2205,7 @@ void pdf_handle_enc(struct pdf_struct *pdf)
2206 2206
 
2207 2207
             if (i != n) {
2208 2208
                 dbg_printhex("too long O", O, n);
2209
-                noisy_warnmsg("too long O", O, n);
2209
+                noisy_warnmsg("too long O: %u", n);
2210 2210
                 break;
2211 2211
             }
2212 2212
         }
... ...
@@ -2214,8 +2213,8 @@ void pdf_handle_enc(struct pdf_struct *pdf)
2214 2214
         n = 0;
2215 2215
         U = pdf_readstring(q, len, "/U", &n, NULL, 0);
2216 2216
         if (!U || n < oulen) {
2217
-            cli_dbgmsg("cli_pdf: invalid U: %d\n", n);
2218
-            noisy_warnmsg("cli_pdf: invalid U: %d\n", n);
2217
+            cli_dbgmsg("cli_pdf: invalid U: %u\n", n);
2218
+            noisy_warnmsg("cli_pdf: invalid U: %u\n", n);
2219 2219
 
2220 2220
             if (U)
2221 2221
                 dbg_printhex("invalid U", U, n);
... ...
@@ -2233,7 +2232,7 @@ void pdf_handle_enc(struct pdf_struct *pdf)
2233 2233
             }
2234 2234
         }
2235 2235
 
2236
-        cli_dbgmsg("cli_pdf: Encrypt R: %d, P %x, length: %d\n", R, P, length);
2236
+        cli_dbgmsg("cli_pdf: Encrypt R: %d, P %x, length: %u\n", R, P, length);
2237 2237
         if (length % 8) {
2238 2238
             cli_dbgmsg("cli_pdf: wrong key length, not multiple of 8\n");
2239 2239
             noisy_warnmsg("cli_pdf: wrong key length, not multiple of 8\n");
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2015 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
2
+ *  Copyright (C) 2015, 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
3 3
  *  Copyright (C) 2007-2013 Sourcefire, Inc.
4 4
  *
5 5
  *  Authors: Nigel Horne
... ...
@@ -160,7 +160,7 @@ int pdf_findobj(struct pdf_struct *pdf);
160 160
 struct pdf_obj *find_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t objid);
161 161
 
162 162
 void pdf_handle_enc(struct pdf_struct *pdf);
163
-char *decrypt_any(struct pdf_struct *pdf, uint32_t id, const char *in, off_t *length, enum enc_method enc_method);
163
+char *decrypt_any(struct pdf_struct *pdf, uint32_t id, const char *in, size_t *length, enum enc_method enc_method);
164 164
 enum enc_method get_enc_method(struct pdf_struct *pdf, struct pdf_obj *obj);
165 165
 enum enc_method parse_enc_method(const char *dict, unsigned len, const char *key, enum enc_method def);
166 166
 
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2016 Cisco and/or its affiliates. All rights reserved.
2
+ *  Copyright (C) 2016-2017 Cisco and/or its affiliates. All rights reserved.
3 3
  *
4 4
  *  Author: Kevin Lin
5 5
  *
... ...
@@ -71,7 +71,7 @@ struct pdf_token {
71 71
     uint32_t flags;    /* tracking flags */
72 72
     uint32_t success;  /* successfully decoded filters */
73 73
 
74
-    uint32_t length;   /* length of current content */
74
+    uint32_t length;   /* length of current content */ /* TODO: transition to size_t */
75 75
     uint8_t *content;  /* content stream */
76 76
 };
77 77
 
... ...
@@ -85,10 +85,10 @@ static  int filter_asciihexdecode(struct pdf_struct *pdf, struct pdf_obj *obj, s
85 85
 static  int filter_decrypt(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, struct pdf_token *token, int mode);
86 86
 static  int filter_lzwdecode(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, struct pdf_token *token);
87 87
 
88
-off_t pdf_decodestream(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, const char *stream, uint32_t streamlen, int xref, int fout, int *rc)
88
+ptrdiff_t pdf_decodestream(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, const char *stream, uint32_t streamlen, int xref, int fout, int *rc)
89 89
 {
90 90
     struct pdf_token *token;
91
-    off_t rv;
91
+    ptrdiff_t rv;
92 92
 
93 93
     if (!stream || !streamlen || fout < 0) {
94 94
         cli_dbgmsg("cli_pdf: no filters or stream on obj %u %u\n", obj->id>>8, obj->id&0xff);
... ...
@@ -127,7 +127,7 @@ off_t pdf_decodestream(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_d
127 127
 
128 128
     cli_dbgmsg("cli_pdf: detected %lu applied filters\n", (long unsigned)(obj->numfilters));
129 129
 
130
-    rv = pdf_decodestream_internal(pdf, obj, params, token);
130
+    rv = (ptrdiff_t)pdf_decodestream_internal(pdf, obj, params, token);
131 131
     /* return is generally ignored */
132 132
     if (rc) {
133 133
         if (rv == CL_VIRUS)
... ...
@@ -727,7 +727,7 @@ static int filter_asciihexdecode(struct pdf_struct *pdf, struct pdf_obj *obj, st
727 727
 static int filter_decrypt(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, struct pdf_token *token, int mode)
728 728
 {
729 729
     char *decrypted;
730
-    off_t length = token->length;
730
+    size_t length = (size_t)token->length;
731 731
     enum enc_method enc = ENC_IDENTITY;
732 732
 
733 733
     if (mode)
... ...
@@ -758,8 +758,8 @@ static int filter_decrypt(struct pdf_struct *pdf, struct pdf_obj *obj, struct pd
758 758
         return CL_EPARSE; /* TODO: what should this value be? CL_SUCCESS would mirror previous behavior */
759 759
     }
760 760
 
761
-    cli_dbgmsg("cli_pdf: decrypted %lld bytes from %lu total bytes\n",
762
-               (long long int)length, (long unsigned)token->length);
761
+    cli_dbgmsg("cli_pdf: decrypted %zu bytes from %u total bytes\n",
762
+               length, token->length);
763 763
 
764 764
 
765 765
     free(token->content);
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2016 Cisco and/or its affiliates. All rights reserved.
2
+ *  Copyright (C) 2016-2017 Cisco and/or its affiliates. All rights reserved.
3 3
  *
4 4
  *  Author: Kevin Lin
5 5
  *
... ...
@@ -36,6 +36,6 @@
36 36
 
37 37
 #include "pdf.h"
38 38
 
39
-off_t pdf_decodestream(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, const char *stream, uint32_t streamlen, int xref, int fout, int *rc);
39
+ptrdiff_t pdf_decodestream(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, const char *stream, uint32_t streamlen, int xref, int fout, int *rc);
40 40
 
41 41
 #endif /* __PDFDECODE_H__ */
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
2
+ *  Copyright (C) 2014, 2017 Cisco and/or its affiliates. All rights reserved.
3 3
  *
4 4
  *  Author: Shawn Webb
5 5
  *
... ...
@@ -226,7 +226,7 @@ int is_object_reference(char *begin, char **endchar, uint32_t *id)
226 226
     return 0;
227 227
 }
228 228
 
229
-static char *pdf_decrypt_string(struct pdf_struct *pdf, struct pdf_obj *obj, const char *in, off_t *length)
229
+static char *pdf_decrypt_string(struct pdf_struct *pdf, struct pdf_obj *obj, const char *in, size_t *length)
230 230
 {
231 231
     enum enc_method enc;
232 232
 
... ...
@@ -242,8 +242,8 @@ static char *pdf_decrypt_string(struct pdf_struct *pdf, struct pdf_obj *obj, con
242 242
 char *pdf_finalize_string(struct pdf_struct *pdf, struct pdf_obj *obj, const char *in, size_t len)
243 243
 {
244 244
     char *wrkstr, *output = NULL;
245
-    size_t wrklen = len, outlen;
246
-    unsigned int i, likelyutf = 0;
245
+    size_t wrklen = len, outlen, i;
246
+    unsigned int likelyutf = 0;
247 247
 
248 248
     if (!in)
249 249
         return NULL;
... ...
@@ -336,9 +336,9 @@ char *pdf_finalize_string(struct pdf_struct *pdf, struct pdf_obj *obj, const cha
336 336
     /* check for encryption and decrypt */
337 337
     if (pdf->flags & (1 << ENCRYPTED_PDF))
338 338
     {
339
-        off_t tmpsz = (off_t)wrklen;
339
+        size_t tmpsz = wrklen;
340 340
         output = pdf_decrypt_string(pdf, obj, wrkstr, &tmpsz);
341
-        outlen = (size_t)tmpsz;
341
+        outlen = tmpsz;
342 342
         free(wrkstr);
343 343
         if (output) {
344 344
             wrkstr = cli_calloc(outlen+1, sizeof(char));