git-svn: trunk@2903
aCaB authored on 2007/03/06 02:49:44... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Mon Mar 5 16:53:27 CET 2007 (acab) |
|
2 |
+----------------------------------- |
|
3 |
+ * libclamav/upx.c: Make gcc -W stfu - minor cosmetic changes |
|
4 |
+ |
|
1 | 5 |
Mon Mar 5 08:57:00 GMT 2007 (njh) |
2 | 6 |
--------------------------------- |
3 | 7 |
* libclamav/mbox.c: Fix another part of bug 255 (please only report one |
... | ... |
@@ -74,7 +74,7 @@ |
74 | 74 |
static int pefromupx (char *src, char *dst, uint32_t *dsize, uint32_t ep, uint32_t upx0, uint32_t upx1, uint32_t magic) |
75 | 75 |
{ |
76 | 76 |
char *imports, *sections, *pehdr, *newbuf; |
77 |
- int sectcnt, upd=1; |
|
77 |
+ unsigned int sectcnt, upd=1; |
|
78 | 78 |
uint32_t realstuffsz, valign; |
79 | 79 |
uint32_t foffset=0xd0+0xf8; |
80 | 80 |
|
... | ... |
@@ -132,8 +132,8 @@ static int pefromupx (char *src, char *dst, uint32_t *dsize, uint32_t ep, uint32 |
132 | 132 |
} |
133 | 133 |
|
134 | 134 |
for (upd = 0; upd <sectcnt ; upd++) { |
135 |
- uint32_t vsize=PESALIGN(cli_readint32(sections+8), valign); |
|
136 |
- uint32_t urva=PEALIGN(cli_readint32(sections+12), valign); |
|
135 |
+ uint32_t vsize=PESALIGN((uint32_t)cli_readint32(sections+8), valign); |
|
136 |
+ uint32_t urva=PEALIGN((uint32_t)cli_readint32(sections+12), valign); |
|
137 | 137 |
|
138 | 138 |
/* Within bounds ? */ |
139 | 139 |
if (!CLI_ISCONTAINED(upx0, realstuffsz, urva, vsize)) { |
... | ... |
@@ -185,9 +185,9 @@ static int pefromupx (char *src, char *dst, uint32_t *dsize, uint32_t ep, uint32 |
185 | 185 |
|
186 | 186 |
/* [doubleebx] */ |
187 | 187 |
|
188 |
-static int doubleebx(char *src, int32_t *myebx, int *scur, int ssize) |
|
188 |
+static int doubleebx(char *src, uint32_t *myebx, uint32_t *scur, uint32_t ssize) |
|
189 | 189 |
{ |
190 |
- int32_t oldebx = *myebx; |
|
190 |
+ uint32_t oldebx = *myebx; |
|
191 | 191 |
|
192 | 192 |
*myebx*=2; |
193 | 193 |
if ( !(oldebx & 0x7fffffff)) { |
... | ... |
@@ -197,19 +197,20 @@ static int doubleebx(char *src, int32_t *myebx, int *scur, int ssize) |
197 | 197 |
*myebx = oldebx*2+1; |
198 | 198 |
*scur+=4; |
199 | 199 |
} |
200 |
- return (oldebx>>31)&1; |
|
200 |
+ return (oldebx>>31); |
|
201 | 201 |
} |
202 | 202 |
|
203 | 203 |
/* [inflate] */ |
204 | 204 |
|
205 | 205 |
int upx_inflate2b(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) |
206 | 206 |
{ |
207 |
- int32_t backbytes, unp_offset = -1, myebx = 0; |
|
208 |
- int scur=0, dcur=0, i, backsize, oob; |
|
209 |
- |
|
207 |
+ int32_t backbytes, unp_offset = -1; |
|
208 |
+ uint32_t backsize, myebx = 0, scur=0, dcur=0, i; |
|
209 |
+ int oob; |
|
210 |
+ |
|
210 | 211 |
while (1) { |
211 | 212 |
while ((oob = doubleebx(src, &myebx, &scur, ssize)) == 1) { |
212 |
- if (scur<0 || scur>=ssize || dcur<0 || dcur>=*dsize) |
|
213 |
+ if (scur>=ssize || dcur>=*dsize) |
|
213 | 214 |
return -1; |
214 | 215 |
dst[dcur++] = src[scur++]; |
215 | 216 |
} |
... | ... |
@@ -229,12 +230,11 @@ int upx_inflate2b(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
229 | 229 |
break; |
230 | 230 |
} |
231 | 231 |
|
232 |
- backsize = 0; |
|
233 | 232 |
backbytes-=3; |
234 | 233 |
|
235 | 234 |
if ( backbytes >= 0 ) { |
236 | 235 |
|
237 |
- if (scur<0 || scur>=ssize) |
|
236 |
+ if (scur>=ssize) |
|
238 | 237 |
return -1; |
239 | 238 |
backbytes<<=8; |
240 | 239 |
backbytes+=(unsigned char)(src[scur++]); |
... | ... |
@@ -245,9 +245,8 @@ int upx_inflate2b(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
245 | 245 |
unp_offset = backbytes; |
246 | 246 |
} |
247 | 247 |
|
248 |
- if ( (oob = doubleebx(src, &myebx, &scur, ssize)) == -1) |
|
248 |
+ if ( (backsize = (uint32_t)doubleebx(src, &myebx, &scur, ssize)) == 0xffffffff) |
|
249 | 249 |
return -1; |
250 |
- backsize = oob; |
|
251 | 250 |
if ( (oob = doubleebx(src, &myebx, &scur, ssize)) == -1) |
252 | 251 |
return -1; |
253 | 252 |
backsize = backsize*2 + oob; |
... | ... |
@@ -268,11 +267,10 @@ int upx_inflate2b(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
268 | 268 |
|
269 | 269 |
backsize++; |
270 | 270 |
|
271 |
- for (i = 0; i < backsize; i++) { |
|
272 |
- if (dcur+i<0 || dcur+i>=*dsize || dcur+unp_offset+i<0 || dcur+unp_offset+i>=*dsize) |
|
273 |
- return -1; |
|
271 |
+ if (!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) || !CLI_ISCONTAINED(dst, *dsize, dst+dcur, backsize) || unp_offset >=0) |
|
272 |
+ return -1; |
|
273 |
+ for (i = 0; i < backsize; i++) |
|
274 | 274 |
dst[dcur + i] = dst[dcur + unp_offset + i]; |
275 |
- } |
|
276 | 275 |
dcur+=backsize; |
277 | 276 |
} |
278 | 277 |
|
... | ... |
@@ -288,12 +286,13 @@ int upx_inflate2b(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
288 | 288 |
|
289 | 289 |
int upx_inflate2d(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) |
290 | 290 |
{ |
291 |
- int32_t backbytes, unp_offset = -1, myebx = 0; |
|
292 |
- int scur=0, dcur=0, i, backsize, oob; |
|
291 |
+ int32_t backbytes, unp_offset = -1; |
|
292 |
+ uint32_t backsize, myebx = 0, scur=0, dcur=0, i; |
|
293 |
+ int oob; |
|
293 | 294 |
|
294 | 295 |
while (1) { |
295 | 296 |
while ( (oob = doubleebx(src, &myebx, &scur, ssize)) == 1) { |
296 |
- if (scur<0 || scur>=ssize || dcur<0 || dcur>=*dsize) |
|
297 |
+ if (scur>=ssize || dcur>=*dsize) |
|
297 | 298 |
return -1; |
298 | 299 |
dst[dcur++] = src[scur++]; |
299 | 300 |
} |
... | ... |
@@ -322,7 +321,7 @@ int upx_inflate2d(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
322 | 322 |
|
323 | 323 |
if ( backbytes >= 0 ) { |
324 | 324 |
|
325 |
- if (scur<0 || scur>=ssize) |
|
325 |
+ if (scur>=ssize) |
|
326 | 326 |
return -1; |
327 | 327 |
backbytes<<=8; |
328 | 328 |
backbytes+=(unsigned char)(src[scur++]); |
... | ... |
@@ -333,9 +332,8 @@ int upx_inflate2d(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
333 | 333 |
backsize = backbytes & 1; |
334 | 334 |
backbytes>>=1; |
335 | 335 |
unp_offset = backbytes; |
336 |
- } |
|
337 |
- else { |
|
338 |
- if ( (backsize = doubleebx(src, &myebx, &scur, ssize)) == -1 ) |
|
336 |
+ } else { |
|
337 |
+ if ( (backsize = (uint32_t)doubleebx(src, &myebx, &scur, ssize)) == 0xffffffff ) |
|
339 | 338 |
return -1; |
340 | 339 |
} |
341 | 340 |
|
... | ... |
@@ -358,11 +356,10 @@ int upx_inflate2d(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
358 | 358 |
backsize++; |
359 | 359 |
|
360 | 360 |
backsize++; |
361 |
- for (i = 0; i < backsize; i++) { |
|
362 |
- if (dcur+i<0 || dcur+i>=*dsize || dcur+unp_offset+i<0 || dcur+unp_offset+i>=*dsize) |
|
363 |
- return -1; |
|
361 |
+ if (!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) || !CLI_ISCONTAINED(dst, *dsize, dst+dcur, backsize) || unp_offset >=0 ) |
|
362 |
+ return -1; |
|
363 |
+ for (i = 0; i < backsize; i++) |
|
364 | 364 |
dst[dcur + i] = dst[dcur + unp_offset + i]; |
365 |
- } |
|
366 | 365 |
dcur+=backsize; |
367 | 366 |
} |
368 | 367 |
|
... | ... |
@@ -378,14 +375,15 @@ int upx_inflate2d(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
378 | 378 |
|
379 | 379 |
int upx_inflate2e(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) |
380 | 380 |
{ |
381 |
- int32_t backbytes, unp_offset = -1, myebx = 0; |
|
382 |
- int scur=0, dcur=0, i, backsize, oob; |
|
381 |
+ int32_t backbytes, unp_offset = -1; |
|
382 |
+ uint32_t backsize, myebx = 0, scur=0, dcur=0, i; |
|
383 |
+ int oob; |
|
383 | 384 |
|
384 | 385 |
for(;;) { |
385 | 386 |
while ( (oob = doubleebx(src, &myebx, &scur, ssize)) ) { |
386 | 387 |
if (oob == -1) |
387 | 388 |
return -1; |
388 |
- if (scur<0 || scur>=ssize || dcur<0 || dcur>=*dsize) |
|
389 |
+ if (scur>=ssize || dcur>=*dsize) |
|
389 | 390 |
return -1; |
390 | 391 |
dst[dcur++] = src[scur++]; |
391 | 392 |
} |
... | ... |
@@ -406,12 +404,11 @@ int upx_inflate2e(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
406 | 406 |
backbytes=backbytes*2+oob; |
407 | 407 |
} |
408 | 408 |
|
409 |
- backsize = 0; |
|
410 | 409 |
backbytes-=3; |
411 | 410 |
|
412 | 411 |
if ( backbytes >= 0 ) { |
413 | 412 |
|
414 |
- if (scur<0 || scur>=ssize) |
|
413 |
+ if (scur>=ssize) |
|
415 | 414 |
return -1; |
416 | 415 |
backbytes<<=8; |
417 | 416 |
backbytes+=(unsigned char)(src[scur++]); |
... | ... |
@@ -422,17 +419,15 @@ int upx_inflate2e(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
422 | 422 |
backsize = backbytes & 1; /* Using backsize to carry on the shifted out bit (UPX uses CF) */ |
423 | 423 |
backbytes>>=1; |
424 | 424 |
unp_offset = backbytes; |
425 |
- } |
|
426 |
- else { |
|
427 |
- if ( (backsize = doubleebx(src, &myebx, &scur, ssize)) == -1 ) |
|
425 |
+ } else { |
|
426 |
+ if ( (backsize = (uint32_t)doubleebx(src, &myebx, &scur, ssize)) == 0xffffffff ) |
|
428 | 427 |
return -1; |
429 | 428 |
} /* Using backsize to carry on the doubleebx result (UPX uses CF) */ |
430 | 429 |
|
431 | 430 |
if (backsize) { /* i.e. IF ( last sar shifted out 1 bit || last doubleebx()==1 ) */ |
432 |
- if ( (backsize = doubleebx(src, &myebx, &scur, ssize)) == -1 ) |
|
431 |
+ if ( (backsize = (uint32_t)doubleebx(src, &myebx, &scur, ssize)) == 0xffffffff ) |
|
433 | 432 |
return -1; |
434 |
- } |
|
435 |
- else { |
|
433 |
+ } else { |
|
436 | 434 |
backsize = 1; |
437 | 435 |
if ((oob = doubleebx(src, &myebx, &scur, ssize)) == -1) |
438 | 436 |
return -1; |
... | ... |
@@ -440,28 +435,27 @@ int upx_inflate2e(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ |
440 | 440 |
if ((oob = doubleebx(src, &myebx, &scur, ssize)) == -1) |
441 | 441 |
return -1; |
442 | 442 |
backsize = 2 + oob; |
443 |
+ } else { |
|
444 |
+ do { |
|
445 |
+ if ((oob = doubleebx(src, &myebx, &scur, ssize)) == -1) |
|
446 |
+ return -1; |
|
447 |
+ backsize = backsize * 2 + oob; |
|
448 |
+ } while ((oob = doubleebx(src, &myebx, &scur, ssize)) == 0); |
|
449 |
+ if (oob == -1) |
|
450 |
+ return -1; |
|
451 |
+ backsize+=2; |
|
443 | 452 |
} |
444 |
- else { |
|
445 |
- do { |
|
446 |
- if ((oob = doubleebx(src, &myebx, &scur, ssize)) == -1) |
|
447 |
- return -1; |
|
448 |
- backsize = backsize * 2 + oob; |
|
449 |
- } while ((oob = doubleebx(src, &myebx, &scur, ssize)) == 0); |
|
450 |
- if (oob == -1) |
|
451 |
- return -1; |
|
452 |
- backsize+=2; |
|
453 |
- } |
|
454 | 453 |
} |
455 | 454 |
|
456 | 455 |
if ( (uint32_t)unp_offset < 0xfffffb00 ) |
457 | 456 |
backsize++; |
458 | 457 |
|
459 | 458 |
backsize+=2; |
460 |
- for (i = 0; i < backsize; i++) { |
|
461 |
- if (dcur+i<0 || dcur+i>=*dsize || dcur+unp_offset+i<0 || dcur+unp_offset+i>=*dsize) |
|
462 |
- return -1; |
|
459 |
+ |
|
460 |
+ if (!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) || !CLI_ISCONTAINED(dst, *dsize, dst+dcur, backsize) || unp_offset >=0 ) |
|
461 |
+ return -1; |
|
462 |
+ for (i = 0; i < backsize; i++) |
|
463 | 463 |
dst[dcur + i] = dst[dcur + unp_offset + i]; |
464 |
- } |
|
465 | 464 |
dcur+=backsize; |
466 | 465 |
} |
467 | 466 |
|