diff options
author | Thomas Jarosch <tomj@simonv.com> | 2011-11-11 17:44:56 +0000 |
---|---|---|
committer | Thomas Jarosch <tomj@simonv.com> | 2011-11-11 17:44:56 +0000 |
commit | 158e14a8c696b29ec7fa21da5b1a801c31c473e9 (patch) | |
tree | 608dfad55016e528cffc01214c8ab2e104b44cf9 /bootloader | |
parent | e5ea0b34186cde4cce5183ffd63a3f1c2eaa7e92 (diff) | |
download | rockbox-158e14a8c696b29ec7fa21da5b1a801c31c473e9.tar.gz rockbox-158e14a8c696b29ec7fa21da5b1a801c31c473e9.zip |
Fix file descriptor leak
Probably not much of an error since it's in the bootloader :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30965 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'bootloader')
-rw-r--r-- | bootloader/main-pp.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/bootloader/main-pp.c b/bootloader/main-pp.c index 03c5aa01b8..78a71cbf96 100644 --- a/bootloader/main-pp.c +++ b/bootloader/main-pp.c | |||
@@ -327,7 +327,10 @@ int load_mi4(unsigned char* buf, char* firmware, unsigned int buffer_size) | |||
327 | printf("mi4 size: %x", mi4header.mi4size); | 327 | printf("mi4 size: %x", mi4header.mi4size); |
328 | 328 | ||
329 | if ((mi4header.mi4size-MI4_HEADER_SIZE) > buffer_size) | 329 | if ((mi4header.mi4size-MI4_HEADER_SIZE) > buffer_size) |
330 | { | ||
331 | close(fd); | ||
330 | return EFILE_TOO_BIG; | 332 | return EFILE_TOO_BIG; |
333 | } | ||
331 | 334 | ||
332 | /* CRC32 */ | 335 | /* CRC32 */ |
333 | printf("CRC32: %x", mi4header.crc32); | 336 | printf("CRC32: %x", mi4header.crc32); |
@@ -342,7 +345,10 @@ int load_mi4(unsigned char* buf, char* firmware, unsigned int buffer_size) | |||
342 | lseek(fd, MI4_HEADER_SIZE, SEEK_SET); | 345 | lseek(fd, MI4_HEADER_SIZE, SEEK_SET); |
343 | rc = read(fd, buf, mi4header.mi4size-MI4_HEADER_SIZE); | 346 | rc = read(fd, buf, mi4header.mi4size-MI4_HEADER_SIZE); |
344 | if(rc < (int)mi4header.mi4size-MI4_HEADER_SIZE) | 347 | if(rc < (int)mi4header.mi4size-MI4_HEADER_SIZE) |
348 | { | ||
349 | close(fd); | ||
345 | return EREAD_IMAGE_FAILED; | 350 | return EREAD_IMAGE_FAILED; |
351 | } | ||
346 | 352 | ||
347 | /* Check CRC32 to see if we have a valid file */ | 353 | /* Check CRC32 to see if we have a valid file */ |
348 | sum = chksum_crc32 (buf, mi4header.mi4size - MI4_HEADER_SIZE); | 354 | sum = chksum_crc32 (buf, mi4header.mi4size - MI4_HEADER_SIZE); |
@@ -350,15 +356,21 @@ int load_mi4(unsigned char* buf, char* firmware, unsigned int buffer_size) | |||
350 | printf("Calculated CRC32: %x", sum); | 356 | printf("Calculated CRC32: %x", sum); |
351 | 357 | ||
352 | if(sum != mi4header.crc32) | 358 | if(sum != mi4header.crc32) |
359 | { | ||
360 | close(fd); | ||
353 | return EBAD_CHKSUM; | 361 | return EBAD_CHKSUM; |
354 | 362 | } | |
363 | |||
355 | if( (mi4header.plaintext + MI4_HEADER_SIZE) != mi4header.mi4size) | 364 | if( (mi4header.plaintext + MI4_HEADER_SIZE) != mi4header.mi4size) |
356 | { | 365 | { |
357 | /* Load encrypted firmware */ | 366 | /* Load encrypted firmware */ |
358 | int key_index = tea_find_key(&mi4header, fd); | 367 | int key_index = tea_find_key(&mi4header, fd); |
359 | 368 | ||
360 | if (key_index < 0) | 369 | if (key_index < 0) |
370 | { | ||
371 | close(fd); | ||
361 | return EINVALID_FORMAT; | 372 | return EINVALID_FORMAT; |
373 | } | ||
362 | 374 | ||
363 | /* Plaintext part is already loaded */ | 375 | /* Plaintext part is already loaded */ |
364 | buf += mi4header.plaintext; | 376 | buf += mi4header.plaintext; |
@@ -373,10 +385,12 @@ int load_mi4(unsigned char* buf, char* firmware, unsigned int buffer_size) | |||
373 | /* Check decryption was successfull */ | 385 | /* Check decryption was successfull */ |
374 | if(le2int(&buf[mi4header.length-mi4header.plaintext-4]) != 0xaa55aa55) | 386 | if(le2int(&buf[mi4header.length-mi4header.plaintext-4]) != 0xaa55aa55) |
375 | { | 387 | { |
388 | close(fd); | ||
376 | return EREAD_IMAGE_FAILED; | 389 | return EREAD_IMAGE_FAILED; |
377 | } | 390 | } |
378 | } | 391 | } |
379 | 392 | ||
393 | close(fd); | ||
380 | return EOK; | 394 | return EOK; |
381 | } | 395 | } |
382 | 396 | ||