Browse code

eliminating warnings. mostly correcting variable types. also correcting struct initialization in a couple instances (var = {0} does not zero the memory on all platforms). Also some minor formatting corrections in areas I was already working. eliminated some unused variables.

Micah Snyder authored on 2017/08/16 03:00:07
Showing 26 changed files
... ...
@@ -15,10 +15,13 @@
15 15
 struct mscab_compressor *
16 16
   mspack_create_cab_compressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_cab_compressor(struct mscab_compressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -15,10 +15,13 @@
15 15
 struct mschm_compressor *
16 16
   mspack_create_chm_compressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_chm_compressor(struct mschm_compressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -1371,16 +1371,22 @@ static int chmd_error(struct mschm_decompressor *base) {
1371 1371
  * are accepted, offsets beyond that cause an error message.
1372 1372
  */
1373 1373
 static int read_off64(off_t *var, unsigned char *mem,
1374
-		      struct mspack_system *sys, struct mspack_file *fh)
1374
+                      struct mspack_system *sys, struct mspack_file *fh)
1375 1375
 {
1376
+  (void) sys;
1377
+
1376 1378
 #ifdef LARGEFILE_SUPPORT
1377
-    *var = EndGetI64(mem);
1379
+  (void) fh;
1380
+
1381
+  *var = EndGetI64(mem);
1378 1382
 #else
1379
-    *var = EndGetI32(mem);
1380
-    if ((*var & 0x80000000) || EndGetI32(mem+4)) {
1381
-	sys->message(fh, (char *)largefile_msg);
1382
-	return 1;
1383
-    }
1383
+  *var = EndGetI32(mem);
1384
+
1385
+  if ((*var & 0x80000000) || EndGetI32(mem + 4))
1386
+  {
1387
+    sys->message(fh, (char *)largefile_msg);
1388
+    return 1;
1389
+  }
1384 1390
 #endif
1385
-    return 0;
1391
+  return 0;
1386 1392
 }
... ...
@@ -15,10 +15,13 @@
15 15
 struct mshlp_compressor *
16 16
   mspack_create_hlp_compressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_hlp_compressor(struct mshlp_compressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -15,10 +15,13 @@
15 15
 struct mshlp_decompressor *
16 16
   mspack_create_hlp_decompressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_hlp_decompressor(struct mshlp_decompressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -15,10 +15,13 @@
15 15
 struct mskwaj_compressor *
16 16
   mspack_create_kwaj_compressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_kwaj_compressor(struct mskwaj_compressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -15,10 +15,13 @@
15 15
 struct mslit_compressor *
16 16
   mspack_create_lit_compressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_lit_compressor(struct mslit_compressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -15,10 +15,13 @@
15 15
 struct mslit_decompressor *
16 16
   mspack_create_lit_decompressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_lit_decompressor(struct mslit_decompressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -15,10 +15,13 @@
15 15
 struct msoab_compressor *
16 16
   mspack_create_oab_compressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_oab_compressor(struct msoab_compressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -118,6 +118,8 @@ static struct mspack_file *msp_open(struct mspack_system *self,
118 118
   struct mspack_file_p *fh;
119 119
   const char *fmode;
120 120
 
121
+  (void) self;
122
+
121 123
   switch (mode) {
122 124
   case MSPACK_SYS_OPEN_READ:   fmode = "rb";  break;
123 125
   case MSPACK_SYS_OPEN_WRITE:  fmode = "wb";  break;
... ...
@@ -201,10 +203,12 @@ static void *msp_alloc(struct mspack_system *self, size_t bytes) {
201 201
 #ifdef DEBUG
202 202
   /* make uninitialised data obvious */
203 203
   char *buf = malloc(bytes + 8);
204
+  (void) self;
204 205
   if (buf) memset(buf, 0xDC, bytes);
205 206
   *((size_t *)buf) = bytes;
206 207
   return &buf[8];
207 208
 #else
209
+  (void) self;
208 210
   return malloc(bytes);
209 211
 #endif
210 212
 }
... ...
@@ -15,10 +15,13 @@
15 15
 struct msszdd_compressor *
16 16
   mspack_create_szdd_compressor(struct mspack_system *sys)
17 17
 {
18
+  (void) sys;
18 19
   /* todo */
19 20
   return NULL;
20 21
 }
21 22
 
22 23
 void mspack_destroy_szdd_compressor(struct msszdd_compressor *self) {
24
+  (void) self;
23 25
   /* todo */
26
+  return;
24 27
 }
... ...
@@ -307,7 +307,6 @@ static int cli_ac_addpatt_recursive(struct cli_matcher *root, struct cli_ac_patt
307 307
 
308 308
 int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
309 309
 {
310
-    struct cli_ac_node *pt;
311 310
     struct cli_ac_patt **newtable;
312 311
     uint16_t len = MIN(root->ac_maxdepth, pattern->length[0]);
313 312
     uint8_t i;
... ...
@@ -1275,7 +1274,7 @@ int cli_ac_initdata(struct cli_ac_data *data, uint32_t partsigs, uint32_t lsigs,
1275 1275
 
1276 1276
     data->partsigs = partsigs;
1277 1277
     if(partsigs) {
1278
-        data->offmatrix = (int32_t ***) cli_calloc(partsigs, sizeof(int32_t **));
1278
+        data->offmatrix = (uint32_t ***) cli_calloc(partsigs, sizeof(uint32_t **));
1279 1279
         if(!data->offmatrix) {
1280 1280
             cli_errmsg("cli_ac_init: Can't allocate memory for data->offmatrix\n");
1281 1281
 
... ...
@@ -1529,7 +1528,6 @@ int lsig_sub_matched(const struct cli_matcher *root, struct cli_ac_data *mdata,
1529 1529
     }
1530 1530
 
1531 1531
     if (ac_lsig->type & CLI_YARA_OFFSET && realoff != CLI_OFF_NONE) {
1532
-        uint32_t * offs;
1533 1532
         struct cli_subsig_matches * ss_matches;
1534 1533
         struct cli_lsig_matches * ls_matches;
1535 1534
         cli_dbgmsg("lsig_sub_matched lsig %u:%u at %u\n", lsigid1, lsigid2, realoff);
... ...
@@ -1624,7 +1622,19 @@ int cli_ac_chkmacro(struct cli_matcher *root, struct cli_ac_data *data, unsigned
1624 1624
 }
1625 1625
 
1626 1626
 
1627
-int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, void **customdata, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, uint32_t offset, cli_file_t ftype, struct cli_matched_type **ftoffset, unsigned int mode, cli_ctx *ctx)
1627
+int cli_ac_scanbuff(
1628
+    const unsigned char *buffer, 
1629
+    uint32_t length, 
1630
+    const char **virname, 
1631
+    void **customdata, 
1632
+    struct cli_ac_result **res, 
1633
+    const struct cli_matcher *root, 
1634
+    struct cli_ac_data *mdata, 
1635
+    uint32_t offset, 
1636
+    cli_file_t ftype, 
1637
+    struct cli_matched_type **ftoffset, 
1638
+    unsigned int mode, 
1639
+    cli_ctx *ctx)
1628 1640
 {
1629 1641
     struct cli_ac_node *current;
1630 1642
     struct cli_ac_list *pattN, *ptN;
... ...
@@ -1632,7 +1642,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1632 1632
     uint32_t i, bp, exptoff[2], realoff, matchstart, matchend;
1633 1633
     uint16_t j;
1634 1634
     uint8_t found, viruses_found = 0;
1635
-    int32_t **offmatrix, swp;
1635
+    uint32_t **offmatrix, swp;
1636 1636
     int type = CL_CLEAN;
1637 1637
     struct cli_ac_result *newres;
1638 1638
     int rc;
... ...
@@ -1741,14 +1751,14 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1741 1741
                                     return CL_EMEM;
1742 1742
                                 }
1743 1743
 
1744
-                                mdata->offmatrix[pt->sigid - 1][0] = cli_malloc(pt->parts * (CLI_DEFAULT_AC_TRACKLEN + 2) * sizeof(int32_t));
1744
+                                mdata->offmatrix[pt->sigid - 1][0] = cli_malloc(pt->parts * (CLI_DEFAULT_AC_TRACKLEN + 2) * sizeof(uint32_t));
1745 1745
                                 if(!mdata->offmatrix[pt->sigid - 1][0]) {
1746 1746
                                     cli_errmsg("cli_ac_scanbuff: Can't allocate memory for mdata->offmatrix[%u][0]\n", pt->sigid - 1);
1747 1747
                                     free(mdata->offmatrix[pt->sigid - 1]);
1748 1748
                                     mdata->offmatrix[pt->sigid - 1] = NULL;
1749 1749
                                     return CL_EMEM;
1750 1750
                                 }
1751
-                                memset(mdata->offmatrix[pt->sigid - 1][0], -1, pt->parts * (CLI_DEFAULT_AC_TRACKLEN + 2) * sizeof(int32_t));
1751
+                                memset(mdata->offmatrix[pt->sigid - 1][0], (uint32_t)-1, pt->parts * (CLI_DEFAULT_AC_TRACKLEN + 2) * sizeof(uint32_t));
1752 1752
                                 mdata->offmatrix[pt->sigid - 1][0][0] = 0;
1753 1753
                                 for(j = 1; j < pt->parts; j++) {
1754 1754
                                     mdata->offmatrix[pt->sigid - 1][j] = mdata->offmatrix[pt->sigid - 1][0] + j * (CLI_DEFAULT_AC_TRACKLEN + 2);
... ...
@@ -1759,7 +1769,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1759 1759
 
1760 1760
                             found = 0;
1761 1761
                             if(pt->partno != 1) {
1762
-                                for(j = 1; j <= CLI_DEFAULT_AC_TRACKLEN + 1 && offmatrix[pt->partno - 2][j] != -1; j++) {
1762
+                                for(j = 1; j <= CLI_DEFAULT_AC_TRACKLEN + 1 && offmatrix[pt->partno - 2][j] != (uint32_t)-1; j++) {
1763 1763
                                     found = j;
1764 1764
                                     if(realoff < offmatrix[pt->partno - 2][j])
1765 1765
                                         found = 0;
... ...
@@ -1810,12 +1820,12 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1810 1810
                                             /* FIXME: the first offset in the array is most likely the correct one but
1811 1811
                                              * it may happen it is not
1812 1812
                                              */
1813
-                                            for(j = 1; j <= CLI_DEFAULT_AC_TRACKLEN + 1 && offmatrix[0][j] != -1; j++)
1813
+                                            for(j = 1; j <= CLI_DEFAULT_AC_TRACKLEN + 1 && offmatrix[0][j] != (uint32_t)-1; j++)
1814 1814
                                                 if(ac_addtype(ftoffset, type, offmatrix[pt->parts - 1][j], ctx))
1815 1815
                                                     return CL_EMEM;
1816 1816
                                         }
1817 1817
 
1818
-                                        memset(offmatrix[0], -1, pt->parts * (CLI_DEFAULT_AC_TRACKLEN + 2) * sizeof(int32_t));
1818
+                                        memset(offmatrix[0], (uint32_t)-1, pt->parts * (CLI_DEFAULT_AC_TRACKLEN + 2) * sizeof(uint32_t));
1819 1819
                                         for(j = 0; j < pt->parts; j++)
1820 1820
                                             offmatrix[j][0] = 0;
1821 1821
                                     }
... ...
@@ -1838,7 +1848,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1838 1838
                                         newres->virname = pt->virname;
1839 1839
                                         newres->customdata = pt->customdata;
1840 1840
                                         newres->next = *res;
1841
-                                        newres->offset = offmatrix[pt->parts - 1][1];
1841
+                                        newres->offset = (off_t)offmatrix[pt->parts - 1][1];
1842 1842
                                         *res = newres;
1843 1843
 
1844 1844
                                         ptN = ptN->next_same;
... ...
@@ -1892,7 +1902,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1892 1892
                                     }
1893 1893
                                     newres->virname = pt->virname;
1894 1894
                                     newres->customdata = pt->customdata;
1895
-                                    newres->offset = realoff;
1895
+                                    newres->offset = (off_t)realoff;
1896 1896
                                     newres->next = *res;
1897 1897
                                     *res = newres;
1898 1898
 
... ...
@@ -1946,7 +1956,8 @@ static int qcompare_fstr(const void *arg, const void *a, const void *b)
1946 1946
 /* returns if level of nesting, end set to MATCHING paren, start AFTER staring paren */
1947 1947
 inline static int find_paren_end(char *hexstr, char **end)
1948 1948
 {
1949
-    int i, nest = 0, level = 0;
1949
+    unsigned long i;
1950
+    int nest = 0, level = 0;
1950 1951
 
1951 1952
     *end = NULL;
1952 1953
     for (i = 0; i < strlen(hexstr); i++) {
... ...
@@ -1970,7 +1981,8 @@ inline static int find_paren_end(char *hexstr, char **end)
1970 1970
  * counts applied to start of expr (not end, i.e. numexpr starts at 1 for the first expr     */
1971 1971
 inline static int ac_analyze_expr(char *hexstr, int *fixed_len, int *sub_len)
1972 1972
 {
1973
-    int i, level = 0, len = 0, numexpr = 1;
1973
+    unsigned long i;
1974
+    int level = 0, len = 0, numexpr = 1;
1974 1975
     int flen, slen;
1975 1976
 
1976 1977
     flen = 1;
... ...
@@ -2026,7 +2038,7 @@ inline static int ac_analyze_expr(char *hexstr, int *fixed_len, int *sub_len)
2026 2026
 
2027 2027
 inline static int ac_uicmp(uint16_t *a, size_t alen, uint16_t *b, size_t blen, int *wild)
2028 2028
 {
2029
-    uint16_t cmp, awild, bwild, side_wild;
2029
+    uint16_t awild, bwild, side_wild;
2030 2030
     size_t i, minlen = MIN(alen, blen);
2031 2031
 
2032 2032
     side_wild = 0;
... ...
@@ -2404,7 +2416,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
2404 2404
     char *pt, *pt2, *hex = NULL, *hexcpy = NULL;
2405 2405
     uint16_t i, j, ppos = 0, pend, *dec, nzpos = 0;
2406 2406
     uint8_t wprefix = 0, zprefix = 1, plen = 0, nzplen = 0;
2407
-    struct cli_ac_special *newspecial, *specialpt, **newtable;
2407
+    struct cli_ac_special *newspecial, **newtable;
2408 2408
     int ret, error = CL_SUCCESS;
2409 2409
 
2410 2410
 
... ...
@@ -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-2009 Sourcefire, Inc.
4 4
  *
5 5
  *  Authors: Tomasz Kojm
... ...
@@ -57,7 +57,7 @@ struct cli_lsig_matches {
57 57
 };
58 58
 
59 59
 struct cli_ac_data {
60
-    int32_t ***offmatrix;
60
+    uint32_t ***offmatrix;
61 61
     uint32_t partsigs, lsigs, reloffsigs;
62 62
     uint32_t **lsigcnt;
63 63
     uint32_t **lsigsuboff_last, **lsigsuboff_first;
... ...
@@ -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
  *  All Rights Reserved.
5 5
  *
... ...
@@ -802,8 +802,11 @@ static int yara_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data
802 802
 {
803 803
     struct cli_ac_lsig *ac_lsig = root->ac_lsigtable[lsid];
804 804
     int rc;
805
-    YR_SCAN_CONTEXT context = {0};
805
+    YR_SCAN_CONTEXT context;
806
+
807
+    (void)hash;
806 808
  
809
+    memset(&context, 0, sizeof(YR_SCAN_CONTEXT));
807 810
     context.fmap = *ctx->fmap;
808 811
     context.file_size = (*ctx->fmap)->len;
809 812
     if (target_info != NULL) {
... ...
@@ -852,9 +855,9 @@ int cli_exp_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data *acd
852 852
 int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres, unsigned char *refhash)
853 853
 {
854 854
     const unsigned char *buff;
855
-    int ret = CL_CLEAN, type = CL_CLEAN, bytes, compute_hash[CLI_HASH_AVAIL_TYPES];
855
+    int ret = CL_CLEAN, type = CL_CLEAN, compute_hash[CLI_HASH_AVAIL_TYPES];
856 856
     unsigned int i = 0, j = 0, bm_offmode = 0;
857
-    uint32_t maxpatlen, offset = 0;
857
+    uint32_t maxpatlen, bytes, offset = 0;
858 858
     struct cli_ac_data gdata, tdata;
859 859
     struct cli_bm_off toff;
860 860
     struct cli_pcre_off gpoff, tpoff;
... ...
@@ -1265,16 +1268,17 @@ int cli_matchmeta(cli_ctx *ctx, const char *fname, size_t fsizec, size_t fsizer,
1265 1265
 	if(cdb->res1 && (cdb->ctype == CL_TYPE_ZIP || cdb->ctype == CL_TYPE_RAR) && cdb->res1 != res1)
1266 1266
 	    continue;
1267 1267
 
1268
-#define CDBRANGE(field, val)						    \
1269
-	if(field[0] != CLI_OFF_ANY) {					    \
1270
-	    if(field[0] == field[1] && field[0] != val)			    \
1271
-		continue;						    \
1272
-	    else if(field[0] != field[1] && ((field[0] && field[0] > val) ||\
1273
-	      (field[1] && field[1] < val)))				    \
1274
-		continue;						    \
1275
-	}
1268
+    #define CDBRANGE(field, val)                                              \
1269
+        if (field[0] != CLI_OFF_ANY)                                          \
1270
+        {                                                                     \
1271
+            if (field[0] == field[1] && field[0] != val)                      \
1272
+                continue;                                                     \
1273
+            else if (field[0] != field[1] && ((field[0] && field[0] > val) || \
1274
+                                            (field[1] && field[1] < val)))    \
1275
+                continue;                                                     \
1276
+        }
1276 1277
 
1277
-	CDBRANGE(cdb->csize, cli_get_container_size(ctx, -1));
1278
+    CDBRANGE(cdb->csize, cli_get_container_size(ctx, -1));
1278 1279
 	CDBRANGE(cdb->fsizec, fsizec);
1279 1280
 	CDBRANGE(cdb->fsizer, fsizer);
1280 1281
 	CDBRANGE(cdb->filepos, filepos);
... ...
@@ -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: Tomasz Kojm
... ...
@@ -143,18 +143,18 @@ struct cli_matcher {
143 143
 
144 144
 struct cli_cdb
145 145
 {
146
-    char	*virname;   /* virus name */
147
-    cli_file_t	ctype;	    /* container type */
148
-    regex_t	name;	    /* filename regex */
149
-    size_t	csize[2];   /* container size (min, max); if csize[0] != csize[1]
150
-			     * then value of 0 makes the field ignored
151
-			     */
152
-    size_t	fsizec[2];  /* file size in container */
153
-    size_t	fsizer[2];  /* real file size */
154
-    int		encrypted;  /* file is encrypted; 2 == ignore */
155
-    int		filepos[2]; /* file position in container */
156
-    int		res1;	    /* reserved / format specific */
157
-    void	*res2;	    /* reserved / format specific */
146
+    char	        *virname;   /* virus name */
147
+    cli_file_t	    ctype;	    /* container type */
148
+    regex_t	        name;	    /* filename regex */
149
+    size_t	        csize[2];   /* container size (min, max); if csize[0] != csize[1]
150
+			                     * then value of 0 makes the field ignored
151
+			                     */
152
+    size_t	        fsizec[2];  /* file size in container */
153
+    size_t	        fsizer[2];  /* real file size */
154
+    int		        encrypted;  /* file is encrypted; 2 == ignore */
155
+    unsigned int    filepos[2]; /* file position in container */
156
+    int		        res1;	    /* reserved / format specific */
157
+    void	        *res2;	    /* reserved / format specific */
158 158
 
159 159
     struct cli_cdb *next;
160 160
 };
... ...
@@ -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-2010 Sourcefire, Inc.
4 4
  *
5 5
  *  Authors: Tomasz Kojm, Trog
... ...
@@ -1171,35 +1171,37 @@ void cli_set_container(cli_ctx *ctx, cli_file_t type, size_t size)
1171 1171
 
1172 1172
 cli_file_t cli_get_container(cli_ctx *ctx, int index)
1173 1173
 {
1174
-    if (index < 0)
1175
-	index = ctx->recursion + index + 1;
1176
-    while (index >= 0 && index <= ctx->recursion) {
1177
-        if (ctx->containers[index].flag & CONTAINER_FLAG_VALID)
1178
-            return ctx->containers[index].type;
1179
-        index--;
1180
-    }
1181
-    return CL_TYPE_ANY;
1174
+	if (index < 0)
1175
+		index = ctx->recursion + index + 1;
1176
+	while (index >= 0 && index <= (int)ctx->recursion)
1177
+	{
1178
+		if (ctx->containers[index].flag & CONTAINER_FLAG_VALID)
1179
+			return ctx->containers[index].type;
1180
+		index--;
1181
+	}
1182
+	return CL_TYPE_ANY;
1182 1183
 }
1183 1184
 
1184 1185
 cli_file_t cli_get_container_intermediate(cli_ctx *ctx, int index)
1185 1186
 {
1186
-   if (index < 0)
1187
-	index = ctx->recursion + index + 1;
1188
-    if (index >= 0 && index <= ctx->recursion)
1189
-	return ctx->containers[index].type;
1190
-    return CL_TYPE_ANY;
1187
+	if (index < 0)
1188
+		index = ctx->recursion + index + 1;
1189
+	if (index >= 0 && index <= (int)ctx->recursion)
1190
+		return ctx->containers[index].type;
1191
+	return CL_TYPE_ANY;
1191 1192
 }
1192 1193
 
1193 1194
 size_t cli_get_container_size(cli_ctx *ctx, int index)
1194 1195
 {
1195
-    if (index < 0)
1196
-	index = ctx->recursion + index + 1;
1197
-    while (index >= 0 && index <= ctx->recursion) {
1198
-        if (ctx->containers[index].flag & CONTAINER_FLAG_VALID)
1199
-            return ctx->containers[index].size;
1200
-        index--;
1201
-    }
1202
-    return ctx->containers[0].size;
1196
+	if (index < 0)
1197
+		index = ctx->recursion + index + 1;
1198
+	while (index >= 0 && index <= (int)ctx->recursion)
1199
+	{
1200
+		if (ctx->containers[index].flag & CONTAINER_FLAG_VALID)
1201
+			return ctx->containers[index].size;
1202
+		index--;
1203
+	}
1204
+	return ctx->containers[0].size;
1203 1205
 }
1204 1206
 
1205 1207
 
... ...
@@ -126,7 +126,8 @@ char *cli_virname(const char *virname, unsigned int official)
126 126
 int cli_sigopts_handler(struct cli_matcher *root, const char *virname, const char *hexsig, uint8_t sigopts, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options)
127 127
 {
128 128
     char *hexcpy, *start, *end;
129
-    int i, ret = CL_SUCCESS;
129
+    unsigned int i;
130
+    int ret = CL_SUCCESS;
130 131
 
131 132
     /*
132 133
      * cyclic loops with cli_parse_add are impossible now as cli_parse_add 
... ...
@@ -303,7 +304,6 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
303 303
     int ret, asterisk = 0, range;
304 304
     unsigned int i, j, hexlen, nest, parts = 0;
305 305
     int mindist = 0, maxdist = 0, error = 0;
306
-    size_t hexcpysz;
307 306
 
308 307
     hexlen = strlen(hexsig);
309 308
     if (hexsig[0] == '$') {
... ...
@@ -1820,7 +1820,7 @@ static int load_oneldb(char *buffer, int chkpua, struct cl_engine *engine, unsig
1820 1820
             sigopts = subtokens[3];
1821 1821
 
1822 1822
         if(sigopts) { /* signature modifiers */
1823
-            for(j = 0; j < strlen(sigopts); j++)
1823
+            for(j = 0; j < (int)strlen(sigopts); j++)
1824 1824
                 switch(sigopts[j]) {
1825 1825
                 case 'i':
1826 1826
                     subsig_opts |= ACPATT_OPTION_NOCASE;
... ...
@@ -2687,7 +2687,7 @@ static int cli_loadmd(FILE *fs, struct cl_engine *engine, unsigned int *signo, i
2687 2687
 
2688 2688
 	/* tokens[6] - not used */
2689 2689
 
2690
-	new->filepos[0] = new->filepos[1] = strcmp(tokens[7], "*") ? atoi(tokens[7]) : (int) CLI_OFF_ANY;
2690
+	new->filepos[0] = new->filepos[1] = strcmp(tokens[7], "*") ? (unsigned int) atoi(tokens[7]) : (unsigned int) CLI_OFF_ANY;
2691 2691
 
2692 2692
 	/* tokens[8] - not used */
2693 2693
 
... ...
@@ -2812,36 +2812,46 @@ static int cli_loadcdb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
2812 2812
 	    break;
2813 2813
 	}
2814 2814
 
2815
-#define CDBRANGE(token_str, dest)					    \
2816
-	if(strcmp(token_str, "*")) {					    \
2817
-	    if(strchr(token_str, '-')) {				    \
2818
-		if(sscanf(token_str, "%u-%u", &n0, &n1) != 2) {		    \
2819
-		    ret = CL_EMALFDB;					    \
2820
-		} else {						    \
2821
-		    dest[0] = n0;					    \
2822
-		    dest[1] = n1;					    \
2823
-		}							    \
2824
-	    } else {							    \
2825
-		if(!cli_isnumber(token_str))				    \
2826
-		    ret = CL_EMALFDB;					    \
2827
-		else							    \
2828
-		    dest[0] = dest[1] = atoi(token_str);		    \
2829
-	    }								    \
2830
-	    if(ret != CL_SUCCESS) {					    \
2831
-		cli_errmsg("cli_loadcdb: Invalid value %s in signature for %s\n",\
2832
-		    token_str, tokens[0]);				    \
2833
-		if(new->name.re_magic)					    \
2834
-		    cli_regfree(&new->name);				    \
2835
-		mpool_free(engine->mempool, new->virname);		    \
2836
-		mpool_free(engine->mempool, new);			    \
2837
-		ret = CL_EMEM;						    \
2838
-		break;							    \
2839
-	    }								    \
2840
-	} else {							    \
2841
-	    dest[0] = dest[1] = CLI_OFF_ANY;				    \
2842
-	}
2815
+    #define CDBRANGE(token_str, dest)                                             \
2816
+        if (strcmp(token_str, "*"))                                               \
2817
+        {                                                                         \
2818
+            if (strchr(token_str, '-'))                                           \
2819
+            {                                                                     \
2820
+                if (sscanf(token_str, "%u-%u", &n0, &n1) != 2)                    \
2821
+                {                                                                 \
2822
+                    ret = CL_EMALFDB;                                             \
2823
+                }                                                                 \
2824
+                else                                                              \
2825
+                {                                                                 \
2826
+                    dest[0] = n0;                                                 \
2827
+                    dest[1] = n1;                                                 \
2828
+                }                                                                 \
2829
+            }                                                                     \
2830
+            else                                                                  \
2831
+            {                                                                     \
2832
+                if (!cli_isnumber(token_str))                                     \
2833
+                    ret = CL_EMALFDB;                                             \
2834
+                else                                                              \
2835
+                    dest[0] = dest[1] = (unsigned int)atoi(token_str);            \
2836
+            }                                                                     \
2837
+            if (ret != CL_SUCCESS)                                                \
2838
+            {                                                                     \
2839
+                cli_errmsg("cli_loadcdb: Invalid value %s in signature for %s\n", \
2840
+                        token_str, tokens[0]);                                    \
2841
+                if (new->name.re_magic)                                           \
2842
+                    cli_regfree(&new->name);                                      \
2843
+                mpool_free(engine->mempool, new->virname);                        \
2844
+                mpool_free(engine->mempool, new);                                 \
2845
+                ret = CL_EMEM;                                                    \
2846
+                break;                                                            \
2847
+            }                                                                     \
2848
+        }                                                                         \
2849
+        else                                                                      \
2850
+        {                                                                         \
2851
+            dest[0] = dest[1] = CLI_OFF_ANY;                                      \
2852
+        }
2843 2853
 
2844
-	CDBRANGE(tokens[2], new->csize);
2854
+    CDBRANGE(tokens[2], new->csize);
2845 2855
 	CDBRANGE(tokens[4], new->fsizec);
2846 2856
 	CDBRANGE(tokens[5], new->fsizer);
2847 2857
 	CDBRANGE(tokens[7], new->filepos);
... ...
@@ -3113,7 +3123,6 @@ static char *parse_yara_hex_string(YR_STRING *string, int *ret)
3113 3113
 {
3114 3114
     char *res, *str, *ovr;
3115 3115
     size_t slen, reslen=0, i, j;
3116
-    int sqr = 0;
3117 3116
 
3118 3117
     if (!(string) || !(string->string)) {
3119 3118
         if (ret) *ret = CL_ENULLARG;
... ...
@@ -3242,6 +3251,7 @@ struct cli_ytable {
3242 3242
 
3243 3243
 static int32_t ytable_lookup(const char *hexsig)
3244 3244
 {
3245
+    (void) hexsig;
3245 3246
     /* TODO - WRITE ME! */
3246 3247
     return -1;
3247 3248
 }
... ...
@@ -3249,7 +3259,6 @@ static int32_t ytable_lookup(const char *hexsig)
3249 3249
 static int ytable_add_attrib(struct cli_ytable *ytable, const char *hexsig, const char *value, int type)
3250 3250
 {
3251 3251
     int32_t lookup;
3252
-    char **attrib;
3253 3252
 
3254 3253
     if (!ytable || !value)
3255 3254
         return CL_ENULLARG;
... ...
@@ -3349,7 +3358,7 @@ static int ytable_add_string(struct cli_ytable *ytable, const char *hexsig)
3349 3349
 
3350 3350
 static void ytable_delete(struct cli_ytable *ytable)
3351 3351
 {
3352
-    uint32_t i;
3352
+    int32_t i;
3353 3353
     if (!ytable)
3354 3354
         return;
3355 3355
 
... ...
@@ -3404,17 +3413,17 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
3404 3404
 {
3405 3405
     YR_STRING *string;
3406 3406
     struct cli_ytable ytable;
3407
-    int str_error = 0, i = 0, ret = CL_SUCCESS;
3407
+    size_t i;
3408
+    int str_error = 0, ret = CL_SUCCESS;
3408 3409
     struct cli_lsig_tdb tdb;
3409 3410
     uint32_t lsigid[2];
3410 3411
     struct cli_matcher *root;
3411 3412
     struct cli_ac_lsig **newtable, *lsig, *tsig = NULL;
3412 3413
     unsigned short target = 0;
3413
-    size_t lsize;
3414 3414
     char *logic = NULL, *target_str = NULL;
3415
-    uint8_t has_short_string;
3416
-    char *exp_op = "|";
3417 3415
     char *newident = NULL;
3416
+    /* size_t lsize; */         // only used in commented out code
3417
+    /* char *exp_op = "|"; */   // only used in commented out code
3418 3418
 
3419 3419
     cli_yaramsg("load_oneyara: attempting to load %s\n", rule->identifier);
3420 3420
 
... ...
@@ -3859,10 +3868,10 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
3859 3859
     tdb.subsigs = ytable.tbl_cnt;
3860 3860
 
3861 3861
     /*** loading step - put things into the AC trie ***/
3862
-    for (i = 0; i < ytable.tbl_cnt; ++i) {
3862
+    for (i = 0; i < (size_t)ytable.tbl_cnt; ++i) {
3863 3863
         lsigid[1] = i;
3864 3864
 
3865
-        cli_yaramsg("%d: [%s] [%s] [%s%s%s%s]\n", i, ytable.table[i]->hexstr, ytable.table[i]->offset,
3865
+        cli_yaramsg("%zu: [%s] [%s] [%s%s%s%s]\n", i, ytable.table[i]->hexstr, ytable.table[i]->offset,
3866 3866
                     (ytable.table[i]->sigopts & ACPATT_OPTION_NOCASE) ? "i" : "",
3867 3867
                     (ytable.table[i]->sigopts & ACPATT_OPTION_FULLWORD) ? "f" : "",
3868 3868
                     (ytable.table[i]->sigopts & ACPATT_OPTION_WIDE) ? "w" : "",
... ...
@@ -3972,7 +3981,7 @@ void cli_yara_free(struct cl_engine * engine)
3972 3972
 //TODO - pua? dbio?
3973 3973
 static int cli_loadyara(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio, const char *filename)
3974 3974
 {
3975
-    YR_COMPILER compiler = {0};
3975
+    YR_COMPILER compiler;
3976 3976
     YR_NAMESPACE ns;
3977 3977
     YR_RULE *rule;
3978 3978
     unsigned int sigs = 0, rules = 0;
... ...
@@ -3983,6 +3992,8 @@ static int cli_loadyara(FILE *fs, struct cl_engine *engine, unsigned int *signo,
3983 3983
     if((rc = cli_initroots(engine, options)))
3984 3984
         return rc;
3985 3985
 
3986
+    memset(&compiler, 0, sizeof(YR_COMPILER));
3987
+
3986 3988
     compiler.last_result = ERROR_SUCCESS;
3987 3989
     STAILQ_INIT(&compiler.rule_q);
3988 3990
     STAILQ_INIT(&compiler.current_rule_string_q);
... ...
@@ -4091,7 +4102,7 @@ static int cli_loadpwdb(FILE *fs, struct cl_engine *engine, unsigned int options
4091 4091
     char *attribs;
4092 4092
     char buffer[FILEBUFF];
4093 4093
     unsigned int line = 0, skip = 0, pwcnt = 0, tokens_count;
4094
-    struct cli_pwdb *new, *ins;
4094
+    struct cli_pwdb *new;
4095 4095
     cl_pwdb_t container;
4096 4096
     struct cli_lsig_tdb tdb;
4097 4097
     int ret = CL_SUCCESS, pwstype;
... ...
@@ -43,7 +43,7 @@
43 43
 #ifdef RAR_HIGH_DEBUG
44 44
 #define rar_dbgmsg printf
45 45
 #else
46
-static void rar_dbgmsg(const char* fmt,...){}
46
+static void rar_dbgmsg(const char* fmt,...){(void)fmt;}
47 47
 #endif
48 48
 
49 49
 static void insert_old_dist(unpack_data_t *unpack_data, unsigned int distance)
... ...
@@ -113,17 +113,16 @@ int rar_unp_read_buf(int fd, unpack_data_t *unpack_data)
113 113
 	
114 114
 	/* Is buffer read pos more than half way? */
115 115
 	if (unpack_data->in_addr > MAX_BUF_SIZE/2) {
116
-		if (data_size > 0) {
117
-			memmove(unpack_data->in_buf, unpack_data->in_buf+unpack_data->in_addr,
118
-					data_size);
119
-		}
116
+		memmove(unpack_data->in_buf, unpack_data->in_buf+unpack_data->in_addr,
117
+				data_size);
118
+
120 119
 		unpack_data->in_addr = 0;
121 120
 		unpack_data->read_top = data_size;
122 121
 	} else {
123 122
 		data_size = unpack_data->read_top;
124 123
 	}
125 124
 	/* RAR2 depends on us only reading upto the end of the current compressed file */
126
-	if (unpack_data->pack_size < ((MAX_BUF_SIZE-data_size)&~0xf)) {
125
+	if (unpack_data->pack_size < (uint32_t)((MAX_BUF_SIZE-data_size)&~0xf)) {
127 126
 		read_size = unpack_data->pack_size;
128 127
 	} else {
129 128
 		read_size = (MAX_BUF_SIZE-data_size)&~0xf;
... ...
@@ -218,7 +217,7 @@ static void unp_write_buf(unpack_data_t *unpack_data)
218 218
 	struct UnpackFilter *flt, *next_filter;
219 219
 	struct rarvm_prepared_program *prg, *next_prg;
220 220
 	uint8_t *filtered_data;
221
-	int i, j;
221
+	size_t i, j;
222 222
 	
223 223
 	rar_dbgmsg("in unp_write_buf\n");
224 224
 	written_border = unpack_data->wr_ptr;
... ...
@@ -541,9 +540,11 @@ static int add_vm_code(unpack_data_t *unpack_data, unsigned int first_byte,
541 541
 			unsigned char *vmcode, int code_size)
542 542
 {
543 543
 	rarvm_input_t rarvm_input;
544
-	unsigned int filter_pos, new_filter, block_start, init_mask, cur_size;
544
+	unsigned int filter_pos, new_filter, block_start, init_mask, cur_size, data_size;
545 545
 	struct UnpackFilter *filter, *stack_filter;
546
-	int i, empty_count, stack_pos, vm_codesize, static_size, data_size;
546
+	size_t i, empty_count, stack_pos;
547
+	unsigned int vm_codesize;
548
+	long static_size;
547 549
 	unsigned char *vm_code, *global_data;
548 550
 	
549 551
 	rar_dbgmsg("in add_vm_code first_byte=0x%x code_size=%d\n", first_byte, code_size);
... ...
@@ -563,7 +564,7 @@ static int add_vm_code(unpack_data_t *unpack_data, unsigned int first_byte,
563 563
 		filter_pos = unpack_data->last_filter;
564 564
 	}
565 565
 	rar_dbgmsg("filter_pos = %u\n", filter_pos);
566
-	if (filter_pos > unpack_data->Filters.num_items ||
566
+	if ((size_t) filter_pos > unpack_data->Filters.num_items ||
567 567
 			filter_pos > unpack_data->old_filter_lengths_size) {
568 568
 		rar_dbgmsg("filter_pos check failed\n");
569 569
 		return FALSE;
... ...
@@ -653,7 +654,7 @@ static int add_vm_code(unpack_data_t *unpack_data, unsigned int first_byte,
653 653
 	}
654 654
 	if (new_filter) {
655 655
 		vm_codesize = rarvm_read_data(&rarvm_input);
656
-		if (vm_codesize >= 0x1000 || vm_codesize == 0 || (vm_codesize > rarvm_input.buf_size) || vm_codesize < 0) {
656
+		if (vm_codesize >= 0x1000 || vm_codesize == 0 || vm_codesize > (unsigned int)rarvm_input.buf_size) {
657 657
 			rar_dbgmsg("ERROR: vm_codesize=0x%x buf_size=0x%x\n", vm_codesize, rarvm_input.buf_size);
658 658
 			return FALSE;
659 659
 		}
... ...
@@ -662,11 +663,11 @@ static int add_vm_code(unpack_data_t *unpack_data, unsigned int first_byte,
662 662
 		    rar_dbgmsg("unrar: add_vm_code: rar_malloc failed for vm_code\n");
663 663
 		    return FALSE;
664 664
 		}
665
-		for (i=0 ; i < vm_codesize ; i++) {
665
+		for (i=0 ; i < (size_t) vm_codesize ; i++) {
666 666
 			vm_code[i] = rarvm_getbits(&rarvm_input) >> 8;
667 667
 			rarvm_addbits(&rarvm_input, 8);
668 668
 		}
669
-		if(!rarvm_prepare(&unpack_data->rarvm_data, &rarvm_input, &vm_code[0], vm_codesize, &filter->prg)) {
669
+		if(!rarvm_prepare(&unpack_data->rarvm_data, &rarvm_input, &vm_code[0], (int) vm_codesize, &filter->prg)) {
670 670
 		    rar_dbgmsg("unrar: add_vm_code: rarvm_prepare failed\n");
671 671
 		    free(vm_code);
672 672
 		    return FALSE;
... ...
@@ -714,10 +715,10 @@ static int add_vm_code(unpack_data_t *unpack_data, unsigned int first_byte,
714 714
 		if (data_size >= 0x10000) {
715 715
 			return FALSE;
716 716
 		}
717
-		cur_size = stack_filter->prg.global_size;
718
-		if (cur_size < data_size+VM_FIXEDGLOBALSIZE) {
719
-			stack_filter->prg.global_size += data_size+VM_FIXEDGLOBALSIZE-cur_size;
720
-			stack_filter->prg.global_data = rar_realloc2(stack_filter->prg.global_data,
717
+		cur_size = (unsigned int)stack_filter->prg.global_size;
718
+		if (cur_size < data_size + VM_FIXEDGLOBALSIZE) {
719
+			stack_filter->prg.global_size += (long)data_size + VM_FIXEDGLOBALSIZE - cur_size;
720
+			stack_filter->prg.global_data = (unsigned char*)rar_realloc2(stack_filter->prg.global_data,
721 721
 				stack_filter->prg.global_size);
722 722
 			if(!stack_filter->prg.global_data) {
723 723
 			    rar_dbgmsg("unrar: add_vm_code: rar_realloc2 failed for stack_filter->prg.global_data\n");
... ...
@@ -725,8 +726,8 @@ static int add_vm_code(unpack_data_t *unpack_data, unsigned int first_byte,
725 725
 			}
726 726
 		}
727 727
 		global_data = &stack_filter->prg.global_data[VM_FIXEDGLOBALSIZE];
728
-		for (i=0 ; i< data_size ; i++) {
729
-			if ((rarvm_input.in_addr+2) > rarvm_input.buf_size) {
728
+		for (i=0 ; i < (size_t)data_size ; i++) {
729
+			if (rarvm_input.in_addr + 2 > rarvm_input.buf_size) {
730 730
 				rar_dbgmsg("Buffer truncated\n");
731 731
 				return FALSE;
732 732
 			}
... ...
@@ -209,7 +209,7 @@ typedef struct unpack_data_tag
209 209
 	rar_filter_array_t Filters;
210 210
 	rar_filter_array_t PrgStack;
211 211
 	int *old_filter_lengths;
212
-	int last_filter, old_filter_lengths_size;
212
+	unsigned int last_filter, old_filter_lengths_size;
213 213
 	int64_t written_size;
214 214
 	int64_t true_size;
215 215
 	int64_t max_size;
... ...
@@ -119,16 +119,18 @@ static void copy_string15(unpack_data_t *unpack_data, unsigned int distance,
119 119
 	}
120 120
 }
121 121
 
122
-static unsigned int decode_num(unpack_data_t *unpack_data, int num, unsigned int start_pos,
122
+static unsigned int decode_num(unpack_data_t *unpack_data, unsigned int num, unsigned int start_pos,
123 123
 			unsigned int *dec_tab, unsigned int *pos_tab)
124 124
 {
125 125
 	int i;
126 126
 	
127
-	for (num&=0xfff0, i=0 ; dec_tab[i] <= num ; i++) {
127
+	for (num &= 0xfff0, i=0; dec_tab[i] <= num; i++) {
128 128
 		start_pos++;
129 129
 	}
130
+
130 131
 	rar_addbits(unpack_data, start_pos);
131
-	return (((num-(i ? dec_tab[i-1]:0)) >> (16-start_pos)) + pos_tab[start_pos]);
132
+	
133
+	return ( ((int)num - (i ? dec_tab[i-1] : 0)) >> (16 - start_pos) ) + pos_tab[start_pos];
132 134
 }
133 135
 
134 136
 static void huff_decode(unpack_data_t *unpack_data)
... ...
@@ -25,7 +25,7 @@
25 25
 #ifdef RAR_HIGH_DEBUG
26 26
 #define rar_dbgmsg printf
27 27
 #else
28
-static void rar_dbgmsg(const char* fmt,...){}
28
+static void rar_dbgmsg(const char* fmt,...){(void)fmt;}
29 29
 #endif
30 30
 
31 31
 void unpack_init_data20(int solid, unpack_data_t *unpack_data)
... ...
@@ -33,7 +33,7 @@ void rar_filter_array_init(rar_filter_array_t *filter_a)
33 33
 
34 34
 void rar_filter_array_reset(rar_filter_array_t *filter_a)
35 35
 {
36
-	int i;
36
+	size_t i;
37 37
 	
38 38
 	if (!filter_a) {
39 39
 		return;
... ...
@@ -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 Sourcefire, Inc.
4 4
  *
5 5
  *  The unRAR sources may be used in any software to handle RAR
... ...
@@ -19,7 +19,7 @@
19 19
 #ifdef RAR_HIGH_DEBUG
20 20
 #define rar_dbgmsg printf
21 21
 #else
22
-static void rar_dbgmsg(const char* fmt,...){}
22
+static void rar_dbgmsg(const char* fmt,...){(void)fmt;}
23 23
 #endif
24 24
 
25 25
 #define RAR_MAX_ALLOCATION 184549376
... ...
@@ -27,7 +27,7 @@
27 27
 #ifdef RAR_HIGH_DEBUG
28 28
 #define rar_dbgmsg printf
29 29
 #else
30
-static void rar_dbgmsg(const char* fmt,...){}
30
+static void rar_dbgmsg(const char* fmt,...){(void)fmt;}
31 31
 #endif
32 32
 
33 33
 #define MAX_O 64
... ...
@@ -754,19 +754,20 @@ static void update1(ppm_data_t *ppm_data, struct state_tag *p, struct ppm_contex
754 754
 static int ppm_decode_symbol1(ppm_data_t *ppm_data, struct ppm_context *context)
755 755
 {
756 756
 	struct state_tag *p;
757
-	int i, hi_cnt, count;
757
+	int i, count;
758
+	uint8_t hi_cnt;
758 759
 	
759 760
 	rar_dbgmsg("in ppm_decode_symbol1\n");
760 761
 	ppm_data->coder.scale = context->con_ut.u.summ_freq;
761 762
 	p = context->con_ut.u.stats;
762 763
 	count = coder_get_current_count(&ppm_data->coder);
763
-	if (count >= ppm_data->coder.scale) {
764
+	if (count >= (int)ppm_data->coder.scale) {
764 765
 		return FALSE;
765 766
 	}
766
-	if (count < (hi_cnt = p->freq)) {
767
-		ppm_data->prev_success = (2 * (ppm_data->coder.high_count=hi_cnt) >
767
+	if (count < (int)(hi_cnt = p->freq)) {
768
+		ppm_data->prev_success = (2 * (ppm_data->coder.high_count=(unsigned int)hi_cnt) >
768 769
 						ppm_data->coder.scale);
769
-		ppm_data->run_length += ppm_data->prev_success;
770
+		ppm_data->run_length += (int)ppm_data->prev_success;
770 771
 		(ppm_data->found_state=p)->freq=(hi_cnt += 4);
771 772
 		context->con_ut.u.summ_freq += 4;
772 773
 		if (hi_cnt > MAX_FREQ) {
... ...
@@ -782,9 +783,9 @@ static int ppm_decode_symbol1(ppm_data_t *ppm_data, struct ppm_context *context)
782 782
 	while ((hi_cnt += (++p)->freq) <= count) {
783 783
 		if (--i == 0) {
784 784
 			ppm_data->hi_bits_flag = ppm_data->hb2flag[ppm_data->found_state->symbol];
785
-			ppm_data->coder.low_count = hi_cnt;
785
+			ppm_data->coder.low_count = (unsigned int)hi_cnt;
786 786
 			ppm_data->char_mask[p->symbol] = ppm_data->esc_count;
787
-			i = (ppm_data->num_masked=context->num_stats) - 1;
787
+			i = (ppm_data->num_masked=(int)context->num_stats) - 1;
788 788
 			ppm_data->found_state = NULL;
789 789
 			do {
790 790
 				ppm_data->char_mask[(--p)->symbol] = ppm_data->esc_count;
... ...
@@ -793,7 +794,7 @@ static int ppm_decode_symbol1(ppm_data_t *ppm_data, struct ppm_context *context)
793 793
 			return TRUE;
794 794
 		}
795 795
 	}
796
-	ppm_data->coder.low_count = (ppm_data->coder.high_count = hi_cnt) - p->freq;
796
+	ppm_data->coder.low_count = ( ppm_data->coder.high_count = (unsigned int)hi_cnt ) - (unsigned int)p->freq;
797 797
 	update1(ppm_data, p, context);
798 798
 	return TRUE;
799 799
 }
... ...
@@ -867,12 +868,13 @@ static struct see2_context_tag *make_esc_freq(ppm_data_t *ppm_data,
867 867
 
868 868
 static int ppm_decode_symbol2(ppm_data_t *ppm_data, struct ppm_context *context)
869 869
 {
870
-	int count, hi_cnt, i;
870
+	int count, i;
871
+	uint8_t hi_cnt;
871 872
 	struct see2_context_tag *psee2c;
872 873
 	struct state_tag *ps[256], **pps, *p;
873 874
 	
874 875
 	rar_dbgmsg("in ppm_decode_symbol2\n");
875
-	i = context->num_stats - ppm_data->num_masked;
876
+	i = (int)context->num_stats - ppm_data->num_masked;
876 877
 	psee2c = make_esc_freq(ppm_data, context, i);
877 878
 	pps = ps;
878 879
 	p = context->con_ut.u.stats - 1;
... ...
@@ -887,28 +889,28 @@ static int ppm_decode_symbol2(ppm_data_t *ppm_data, struct ppm_context *context)
887 887
 	} while (--i);
888 888
 	ppm_data->coder.scale += hi_cnt;
889 889
 	count = coder_get_current_count(&ppm_data->coder);
890
-	if (count >= ppm_data->coder.scale) {
890
+	if (count >= (int)ppm_data->coder.scale) {
891 891
 		return FALSE;
892 892
 	}
893 893
 	p=*(pps=ps);
894
-	if (count < hi_cnt) {
894
+	if (count < (int)hi_cnt) {
895 895
 		hi_cnt = 0;
896
-		while ((hi_cnt += p->freq) <= count) {
896
+		while ((int)(hi_cnt += p->freq) <= count) {
897 897
 			p=*++pps;
898 898
 		}
899
-		ppm_data->coder.low_count = (ppm_data->coder.high_count=hi_cnt) - p->freq;
899
+		ppm_data->coder.low_count = (ppm_data->coder.high_count=(unsigned int)hi_cnt) - (unsigned int)p->freq;
900 900
 		update(psee2c);
901 901
 		update2(ppm_data, p, context);
902 902
 	} else {
903
-		ppm_data->coder.low_count = hi_cnt;
904
-		ppm_data->coder.high_count = ppm_data->coder.scale;
905
-		i = context->num_stats - ppm_data->num_masked;
903
+		ppm_data->coder.low_count = (unsigned int)hi_cnt;
904
+		ppm_data->coder.high_count = (unsigned int)ppm_data->coder.scale;
905
+		i = (int)context->num_stats - ppm_data->num_masked;
906 906
 		pps--;
907 907
 		do {
908 908
 			ppm_data->char_mask[(*++pps)->symbol] = ppm_data->esc_count;
909 909
 		} while (--i);
910 910
 		psee2c->summ += ppm_data->coder.scale;
911
-		ppm_data->num_masked = context->num_stats;
911
+		ppm_data->num_masked = (int)context->num_stats;
912 912
 	}
913 913
 	return TRUE;
914 914
 }
... ...
@@ -1013,7 +1015,7 @@ int ppm_decode_char(ppm_data_t *ppm_data, int fd, unpack_data_t *unpack_data)
1013 1013
 					ppm_data->sub_alloc.heap_end) {
1014 1014
 				return -1;
1015 1015
 			}
1016
-		} while (ppm_data->min_context->num_stats == ppm_data->num_masked);
1016
+		} while ((int)ppm_data->min_context->num_stats == ppm_data->num_masked);
1017 1017
 		if (!ppm_decode_symbol2(ppm_data, ppm_data->min_context)) {
1018 1018
 			return -1;
1019 1019
 		}
... ...
@@ -29,7 +29,7 @@
29 29
 #ifdef RAR_HIGH_DEBUG
30 30
 #define rar_dbgmsg printf
31 31
 #else
32
-static void rar_dbgmsg(const char* fmt,...){}
32
+static void rar_dbgmsg(const char* fmt,...){(void)fmt;}
33 33
 #endif
34 34
 
35 35
 #define VMCF_OP0             0
... ...
@@ -42,6 +42,28 @@ static void rar_dbgmsg(const char* fmt,...){}
42 42
 #define VMCF_USEFLAGS       32
43 43
 #define VMCF_CHFLAGS        64
44 44
 
45
+#define UINT32(x)  (sizeof(uint32_t)==4 ? (uint32_t)(x):((x)&0xffffffff))
46
+
47
+#if WORDS_BIGENDIAN == 0
48
+#define GET_VALUE(byte_mode,addr) ((byte_mode) ? (*(unsigned char *)(addr)) : UINT32((*(unsigned int *)(addr))))
49
+#else
50
+#define GET_VALUE(byte_mode,addr) ((byte_mode) ? (*(unsigned char *)(addr)) : (((unsigned char *)addr)[0] | ((unsigned char *)addr)[1]<<8 | ((unsigned char *)addr)[2]<<16 | ((unsigned char *)addr)[3]<<24))
51
+#endif
52
+		
53
+#if WORDS_BIGENDIAN == 0
54
+#define SET_VALUE(byte_mode,addr,value) (void)(((byte_mode) ? (*(unsigned char *)(addr)=(value)):(*(uint32_t *)(addr)=((uint32_t)(value)))))
55
+#else
56
+#define SET_VALUE(byte_mode,addr,value) rarvm_set_value(byte_mode, (unsigned int *)addr, value);
57
+#endif
58
+				
59
+#define SET_IP(IP)                        \
60
+  if ((IP)>=(unsigned int)code_size)      \
61
+    return TRUE;                          \
62
+  if (--max_ops<=0)                       \
63
+    return FALSE;                         \
64
+  cmd=prepared_code+(IP);
65
+
66
+
45 67
 static uint8_t vm_cmdflags[]=
46 68
 {
47 69
   /* VM_MOV   */ VMCF_OP2 | VMCF_BYTEMODE                                ,
... ...
@@ -86,37 +108,6 @@ static uint8_t vm_cmdflags[]=
86 86
   /* VM_PRINT */ VMCF_OP0
87 87
 };
88 88
 
89
-#define UINT32(x)  (sizeof(uint32_t)==4 ? (uint32_t)(x):((x)&0xffffffff))
90
-
91
-#if WORDS_BIGENDIAN == 0
92
-#define GET_VALUE(byte_mode,addr) ((byte_mode) ? (*(unsigned char *)(addr)) : UINT32((*(unsigned int *)(addr))))
93
-#else
94
-#define GET_VALUE(byte_mode,addr) ((byte_mode) ? (*(unsigned char *)(addr)) : (((unsigned char *)addr)[0] | ((unsigned char *)addr)[1]<<8 | ((unsigned char *)addr)[2]<<16 | ((unsigned char *)addr)[3]<<24))
95
-#endif
96
-
97
-void rarvm_set_value(int byte_mode, unsigned int *addr, unsigned int value)
98
-{
99
-	if (byte_mode) {
100
-		*(unsigned char *)addr=value;
101
-	} else {
102
-#if WORDS_BIGENDIAN == 0
103
-		*(uint32_t *)addr = value;
104
-#else
105
-		((unsigned char *)addr)[0]=(unsigned char)value;
106
-		((unsigned char *)addr)[1]=(unsigned char)(value>>8);
107
-		((unsigned char *)addr)[2]=(unsigned char)(value>>16);
108
-		((unsigned char *)addr)[3]=(unsigned char)(value>>24);
109
-#endif
110
-	}
111
-}
112
-
113
-		
114
-#if WORDS_BIGENDIAN == 0
115
-#define SET_VALUE(byte_mode,addr,value) (void)(((byte_mode) ? (*(unsigned char *)(addr)=(value)):(*(uint32_t *)(addr)=((uint32_t)(value)))))
116
-#else
117
-#define SET_VALUE(byte_mode,addr,value) rarvm_set_value(byte_mode, (unsigned int *)addr, value);
118
-#endif
119
-
120 89
 const uint32_t crc_tab[256]={
121 90
 	0x0,        0x77073096, 0xee0e612c, 0x990951ba, 0x76dc419,  0x706af48f, 0xe963a535, 0x9e6495a3,
122 91
 	0xedb8832,  0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x9b64c2b,  0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
... ...
@@ -152,10 +143,26 @@ const uint32_t crc_tab[256]={
152 152
 	0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
153 153
 };
154 154
 
155
+void rarvm_set_value(int byte_mode, unsigned int *addr, unsigned int value)
156
+{
157
+	if (byte_mode) {
158
+		*(unsigned char *)addr=value;
159
+	} else {
160
+#if WORDS_BIGENDIAN == 0
161
+		*(uint32_t *)addr = value;
162
+#else
163
+		((unsigned char *)addr)[0]=(unsigned char)value;
164
+		((unsigned char *)addr)[1]=(unsigned char)(value>>8);
165
+		((unsigned char *)addr)[2]=(unsigned char)(value>>16);
166
+		((unsigned char *)addr)[3]=(unsigned char)(value>>24);
167
+#endif
168
+	}
169
+}
170
+
155 171
 uint32_t rar_crc(uint32_t start_crc, void *addr, uint32_t size)
156 172
 {
157 173
 	unsigned char *data;
158
-	int i;
174
+	uint32_t i;
159 175
 
160 176
 	data = addr;
161 177
 #if WORDS_BIGENDIAN == 0
... ...
@@ -576,13 +583,6 @@ static void execute_standard_filter(rarvm_data_t *rarvm_data, rarvm_standard_fil
576 576
 		break;
577 577
 	}
578 578
 }
579
-				
580
-#define SET_IP(IP)                      \
581
-  if ((IP)>=code_size)                   \
582
-    return TRUE;                       \
583
-  if (--max_ops<=0)                  \
584
-    return FALSE;                      \
585
-  cmd=prepared_code+(IP);
586 579
 
587 580
 static int rarvm_execute_code(rarvm_data_t *rarvm_data,
588 581
 		struct rarvm_prepared_command *prepared_code, int code_size)
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  *  Interface to libclamunrar
3
- *  Copyright (C) 2015 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
3
+ *  Copyright (C) 2015, 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
4 4
  *  Copyright (C) 2007-2013 Sourcefire, Inc.
5 5
  *  Authors: Trog, Torok Edvin, Tomasz Kojm
6 6
  *
... ...
@@ -53,7 +53,7 @@ static uint32_t unrar_endian_convert_32(uint32_t v)
53 53
 #ifdef RAR_DEBUG_MODE
54 54
 #define unrar_dbgmsg printf
55 55
 #else
56
-static void unrar_dbgmsg(const char* fmt,...){}
56
+static void unrar_dbgmsg(const char* fmt,...){(void)fmt;}
57 57
 #endif
58 58
 
59 59
 static void *read_header(int fd, header_type hdr_type)
... ...
@@ -386,6 +386,7 @@ int unrar_extract_next_prepare(unrar_state_t *state, const char *dirname)
386 386
 	int ofd;
387 387
 	unrar_metadata_t *new_metadata;
388 388
 
389
+	(void)dirname;
389 390
 
390 391
     state->file_header = read_block(state->fd, FILE_HEAD);
391 392
     if(!state->file_header)