pkg_install-20090301: Plug a number of file descriptor leaks.diff -r1.81 -r1.82 pkgsrc/pkgtools/pkg_install/files/add/perform.c
(joerg)
@@ -1,22 +1,22 @@ | @@ -1,22 +1,22 @@ | |||
1 | /* $NetBSD: perform.c,v 1.81 2009/02/28 16:03:56 joerg Exp $ */ | 1 | /* $NetBSD: perform.c,v 1.82 2009/03/02 14:59:14 joerg Exp $ */ | |
2 | #if HAVE_CONFIG_H | 2 | #if HAVE_CONFIG_H | |
3 | #include "config.h" | 3 | #include "config.h" | |
4 | #endif | 4 | #endif | |
5 | #include <nbcompat.h> | 5 | #include <nbcompat.h> | |
6 | #if HAVE_SYS_CDEFS_H | 6 | #if HAVE_SYS_CDEFS_H | |
7 | #include <sys/cdefs.h> | 7 | #include <sys/cdefs.h> | |
8 | #endif | 8 | #endif | |
9 | __RCSID("$NetBSD: perform.c,v 1.81 2009/02/28 16:03:56 joerg Exp $"); | 9 | __RCSID("$NetBSD: perform.c,v 1.82 2009/03/02 14:59:14 joerg Exp $"); | |
10 | 10 | |||
11 | /*- | 11 | /*- | |
12 | * Copyright (c) 2003 Grant Beattie <grant@NetBSD.org> | 12 | * Copyright (c) 2003 Grant Beattie <grant@NetBSD.org> | |
13 | * Copyright (c) 2005 Dieter Baron <dillo@NetBSD.org> | 13 | * Copyright (c) 2005 Dieter Baron <dillo@NetBSD.org> | |
14 | * Copyright (c) 2007 Roland Illig <rillig@NetBSD.org> | 14 | * Copyright (c) 2007 Roland Illig <rillig@NetBSD.org> | |
15 | * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org> | 15 | * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org> | |
16 | * All rights reserved. | 16 | * All rights reserved. | |
17 | * | 17 | * | |
18 | * Redistribution and use in source and binary forms, with or without | 18 | * Redistribution and use in source and binary forms, with or without | |
19 | * modification, are permitted provided that the following conditions | 19 | * modification, are permitted provided that the following conditions | |
20 | * are met: | 20 | * are met: | |
21 | * | 21 | * | |
22 | * 1. Redistributions of source code must retain the above copyright | 22 | * 1. Redistributions of source code must retain the above copyright | |
@@ -347,26 +347,27 @@ check_already_installed(struct pkg_task | @@ -347,26 +347,27 @@ check_already_installed(struct pkg_task | |||
347 | return -1; | 347 | return -1; | |
348 | 348 | |||
349 | /* We can only arrive here for explicitly requested packages. */ | 349 | /* We can only arrive here for explicitly requested packages. */ | |
350 | if (!Automatic && is_automatic_installed(pkg->pkgname)) { | 350 | if (!Automatic && is_automatic_installed(pkg->pkgname)) { | |
351 | if (Fake || | 351 | if (Fake || | |
352 | mark_as_automatic_installed(pkg->pkgname, 0) == 0) | 352 | mark_as_automatic_installed(pkg->pkgname, 0) == 0) | |
353 | warnx("package `%s' was already installed as " | 353 | warnx("package `%s' was already installed as " | |
354 | "dependency, now marked as installed " | 354 | "dependency, now marked as installed " | |
355 | "manually", pkg->pkgname); | 355 | "manually", pkg->pkgname); | |
356 | } else { | 356 | } else { | |
357 | warnx("package `%s' already recorded as installed", | 357 | warnx("package `%s' already recorded as installed", | |
358 | pkg->pkgname); | 358 | pkg->pkgname); | |
359 | } | 359 | } | |
360 | close(fd); | |||
360 | return 0; | 361 | return 0; | |
361 | 362 | |||
362 | } | 363 | } | |
363 | 364 | |||
364 | static int | 365 | static int | |
365 | check_other_installed(struct pkg_task *pkg) | 366 | check_other_installed(struct pkg_task *pkg) | |
366 | { | 367 | { | |
367 | FILE *f, *f_pkg; | 368 | FILE *f, *f_pkg; | |
368 | size_t len; | 369 | size_t len; | |
369 | char *pkgbase, *iter, *filename; | 370 | char *pkgbase, *iter, *filename; | |
370 | package_t plist; | 371 | package_t plist; | |
371 | plist_t *p; | 372 | plist_t *p; | |
372 | int status; | 373 | int status; | |
@@ -539,26 +540,27 @@ write_meta_data(struct pkg_task *pkg) | @@ -539,26 +540,27 @@ write_meta_data(struct pkg_task *pkg) | |||
539 | (void)unlink(filename); | 540 | (void)unlink(filename); | |
540 | fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, descr->perm); | 541 | fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, descr->perm); | |
541 | if (fd == -1) { | 542 | if (fd == -1) { | |
542 | warn("Can't open meta data file: %s", filename); | 543 | warn("Can't open meta data file: %s", filename); | |
543 | return -1; | 544 | return -1; | |
544 | } | 545 | } | |
545 | len = strlen(*target); | 546 | len = strlen(*target); | |
546 | do { | 547 | do { | |
547 | ret = write(fd, *target, len); | 548 | ret = write(fd, *target, len); | |
548 | if (ret == -1) { | 549 | if (ret == -1) { | |
549 | warn("Can't write meta data file: %s", | 550 | warn("Can't write meta data file: %s", | |
550 | filename); | 551 | filename); | |
551 | free(filename); | 552 | free(filename); | |
553 | close(fd); | |||
552 | return -1; | 554 | return -1; | |
553 | } | 555 | } | |
554 | len -= ret; | 556 | len -= ret; | |
555 | } while (ret > 0); | 557 | } while (ret > 0); | |
556 | if (close(fd) == -1) { | 558 | if (close(fd) == -1) { | |
557 | warn("Can't close meta data file: %s", filename); | 559 | warn("Can't close meta data file: %s", filename); | |
558 | free(filename); | 560 | free(filename); | |
559 | return -1; | 561 | return -1; | |
560 | } | 562 | } | |
561 | free(filename); | 563 | free(filename); | |
562 | } | 564 | } | |
563 | 565 | |||
564 | return 0; | 566 | return 0; | |
@@ -761,32 +763,34 @@ pkg_register_depends(struct pkg_task *pk | @@ -761,32 +763,34 @@ pkg_register_depends(struct pkg_task *pk | |||
761 | if (Fake) | 763 | if (Fake) | |
762 | return; | 764 | return; | |
763 | 765 | |||
764 | if (pkg->other_version != NULL) | 766 | if (pkg->other_version != NULL) | |
765 | return; /* XXX It's using the old dependencies. */ | 767 | return; /* XXX It's using the old dependencies. */ | |
766 | 768 | |||
767 | text = xasprintf("%s\n", pkg->pkgname); | 769 | text = xasprintf("%s\n", pkg->pkgname); | |
768 | text_len = strlen(text); | 770 | text_len = strlen(text); | |
769 | 771 | |||
770 | for (i = 0; i < pkg->dep_length; ++i) { | 772 | for (i = 0; i < pkg->dep_length; ++i) { | |
771 | required_by = pkgdb_pkg_file(pkg->dependencies[i], REQUIRED_BY_FNAME); | 773 | required_by = pkgdb_pkg_file(pkg->dependencies[i], REQUIRED_BY_FNAME); | |
772 | 774 | |||
773 | fd = open(required_by, O_WRONLY | O_APPEND | O_CREAT, 0644); | 775 | fd = open(required_by, O_WRONLY | O_APPEND | O_CREAT, 0644); | |
774 | if (fd == -1) | 776 | if (fd == -1) { | |
775 | warn("can't open dependency file '%s'," | 777 | warn("can't open dependency file '%s'," | |
776 | "registration is incomplete!", required_by); | 778 | "registration is incomplete!", required_by); | |
777 | else if (write(fd, text, text_len) != text_len) | 779 | close(fd); | |
780 | } else if (write(fd, text, text_len) != text_len) { | |||
778 | warn("can't write to dependency file `%s'", required_by); | 781 | warn("can't write to dependency file `%s'", required_by); | |
779 | else if (close(fd) == -1) | 782 | close(fd); | |
783 | } else if (close(fd) == -1) | |||
780 | warn("cannot close file %s", required_by); | 784 | warn("cannot close file %s", required_by); | |
781 | 785 | |||
782 | free(required_by); | 786 | free(required_by); | |
783 | } | 787 | } | |
784 | 788 | |||
785 | free(text); | 789 | free(text); | |
786 | } | 790 | } | |
787 | 791 | |||
788 | /* | 792 | /* | |
789 | * Reduce the result from uname(3) to a canonical form. | 793 | * Reduce the result from uname(3) to a canonical form. | |
790 | */ | 794 | */ | |
791 | static void | 795 | static void | |
792 | normalise_platform(struct utsname *host_name) | 796 | normalise_platform(struct utsname *host_name) |
@@ -1,23 +1,23 @@ | @@ -1,23 +1,23 @@ | |||
1 | /* $NetBSD: pkcs7.c,v 1.3 2009/02/16 20:59:11 joerg Exp $ */ | 1 | /* $NetBSD: pkcs7.c,v 1.4 2009/03/02 14:59:14 joerg Exp $ */ | |
2 | #if HAVE_CONFIG_H | 2 | #if HAVE_CONFIG_H | |
3 | #include "config.h" | 3 | #include "config.h" | |
4 | #endif | 4 | #endif | |
5 | #include <nbcompat.h> | 5 | #include <nbcompat.h> | |
6 | #if HAVE_SYS_CDEFS_H | 6 | #if HAVE_SYS_CDEFS_H | |
7 | #include <sys/cdefs.h> | 7 | #include <sys/cdefs.h> | |
8 | #endif | 8 | #endif | |
9 | 9 | |||
10 | __RCSID("$NetBSD: pkcs7.c,v 1.3 2009/02/16 20:59:11 joerg Exp $"); | 10 | __RCSID("$NetBSD: pkcs7.c,v 1.4 2009/03/02 14:59:14 joerg Exp $"); | |
11 | 11 | |||
12 | /*- | 12 | /*- | |
13 | * Copyright (c) 2004, 2008 The NetBSD Foundation, Inc. | 13 | * Copyright (c) 2004, 2008 The NetBSD Foundation, Inc. | |
14 | * All rights reserved. | 14 | * All rights reserved. | |
15 | * | 15 | * | |
16 | * This code is derived from software contributed to The NetBSD Foundation | 16 | * This code is derived from software contributed to The NetBSD Foundation | |
17 | * by Love Hörnquist Åstrand <lha@it.su.se> | 17 | * by Love Hörnquist Åstrand <lha@it.su.se> | |
18 | * | 18 | * | |
19 | * Redistribution and use in source and binary forms, with or without | 19 | * Redistribution and use in source and binary forms, with or without | |
20 | * modification, are permitted provided that the following conditions | 20 | * modification, are permitted provided that the following conditions | |
21 | * are met: | 21 | * are met: | |
22 | * 1. Redistributions of source code must retain the above copyright | 22 | * 1. Redistributions of source code must retain the above copyright | |
23 | * notice, this list of conditions and the following disclaimer. | 23 | * notice, this list of conditions and the following disclaimer. | |
@@ -95,26 +95,27 @@ file_to_certs(const char *file) | @@ -95,26 +95,27 @@ file_to_certs(const char *file) | |||
95 | for (;;) { | 95 | for (;;) { | |
96 | X509 *cert; | 96 | X509 *cert; | |
97 | 97 | |||
98 | cert = PEM_read_X509(f, NULL, NULL, NULL); | 98 | cert = PEM_read_X509(f, NULL, NULL, NULL); | |
99 | if (cert == NULL) { | 99 | if (cert == NULL) { | |
100 | ret = ERR_GET_REASON(ERR_peek_error()); | 100 | ret = ERR_GET_REASON(ERR_peek_error()); | |
101 | if (ret == PEM_R_NO_START_LINE) { | 101 | if (ret == PEM_R_NO_START_LINE) { | |
102 | /* End of file reached. no error */ | 102 | /* End of file reached. no error */ | |
103 | ERR_clear_error(); | 103 | ERR_clear_error(); | |
104 | break; | 104 | break; | |
105 | } | 105 | } | |
106 | sk_X509_free(certs); | 106 | sk_X509_free(certs); | |
107 | warnx("Can't read certificate in file: %s", file); | 107 | warnx("Can't read certificate in file: %s", file); | |
108 | fclose(f); | |||
108 | return NULL; | 109 | return NULL; | |
109 | } | 110 | } | |
110 | sk_X509_insert(certs, cert, sk_X509_num(certs)); | 111 | sk_X509_insert(certs, cert, sk_X509_num(certs)); | |
111 | } | 112 | } | |
112 | 113 | |||
113 | fclose(f); | 114 | fclose(f); | |
114 | 115 | |||
115 | if (sk_X509_num(certs) == 0) { | 116 | if (sk_X509_num(certs) == 0) { | |
116 | sk_X509_free(certs); | 117 | sk_X509_free(certs); | |
117 | certs = NULL; | 118 | certs = NULL; | |
118 | warnx("No certificate found in file %s", file); | 119 | warnx("No certificate found in file %s", file); | |
119 | } | 120 | } | |
120 | 121 |
@@ -1,23 +1,23 @@ | @@ -1,23 +1,23 @@ | |||
1 | /* $NetBSD: pkg_signature.c,v 1.5 2009/02/13 13:17:41 joerg Exp $ */ | 1 | /* $NetBSD: pkg_signature.c,v 1.6 2009/03/02 14:59:14 joerg Exp $ */ | |
2 | 2 | |||
3 | #if HAVE_CONFIG_H | 3 | #if HAVE_CONFIG_H | |
4 | #include "config.h" | 4 | #include "config.h" | |
5 | #endif | 5 | #endif | |
6 | #include <nbcompat.h> | 6 | #include <nbcompat.h> | |
7 | #if HAVE_SYS_CDEFS_H | 7 | #if HAVE_SYS_CDEFS_H | |
8 | #include <sys/cdefs.h> | 8 | #include <sys/cdefs.h> | |
9 | #endif | 9 | #endif | |
10 | __RCSID("$NetBSD: pkg_signature.c,v 1.5 2009/02/13 13:17:41 joerg Exp $"); | 10 | __RCSID("$NetBSD: pkg_signature.c,v 1.6 2009/03/02 14:59:14 joerg Exp $"); | |
11 | 11 | |||
12 | /*- | 12 | /*- | |
13 | * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. | 13 | * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. | |
14 | * All rights reserved. | 14 | * All rights reserved. | |
15 | * | 15 | * | |
16 | * Redistribution and use in source and binary forms, with or without | 16 | * Redistribution and use in source and binary forms, with or without | |
17 | * modification, are permitted provided that the following conditions | 17 | * modification, are permitted provided that the following conditions | |
18 | * are met: | 18 | * are met: | |
19 | * | 19 | * | |
20 | * 1. Redistributions of source code must retain the above copyright | 20 | * 1. Redistributions of source code must retain the above copyright | |
21 | * notice, this list of conditions and the following disclaimer. | 21 | * notice, this list of conditions and the following disclaimer. | |
22 | * 2. Redistributions in binary form must reproduce the above copyright | 22 | * 2. Redistributions in binary form must reproduce the above copyright | |
23 | * notice, this list of conditions and the following disclaimer in | 23 | * notice, this list of conditions and the following disclaimer in | |
@@ -604,26 +604,28 @@ pkg_sign_x509(const char *name, const ch | @@ -604,26 +604,28 @@ pkg_sign_x509(const char *name, const ch | |||
604 | if (i + sizeof(block) < size) | 604 | if (i + sizeof(block) < size) | |
605 | block_len = sizeof(block); | 605 | block_len = sizeof(block); | |
606 | else | 606 | else | |
607 | block_len = size % sizeof(block); | 607 | block_len = size % sizeof(block); | |
608 | if (read(fd, block, block_len) != block_len) | 608 | if (read(fd, block, block_len) != block_len) | |
609 | err(2, "short read"); | 609 | err(2, "short read"); | |
610 | archive_write_data(pkg, block, block_len); | 610 | archive_write_data(pkg, block, block_len); | |
611 | } | 611 | } | |
612 | archive_write_finish_entry(pkg); | 612 | archive_write_finish_entry(pkg); | |
613 | archive_entry_free(entry); | 613 | archive_entry_free(entry); | |
614 | 614 | |||
615 | archive_write_finish(pkg); | 615 | archive_write_finish(pkg); | |
616 | 616 | |||
617 | close(fd); | |||
618 | ||||
617 | exit(0); | 619 | exit(0); | |
618 | } | 620 | } | |
619 | #endif | 621 | #endif | |
620 | 622 | |||
621 | void | 623 | void | |
622 | pkg_sign_gpg(const char *name, const char *output) | 624 | pkg_sign_gpg(const char *name, const char *output) | |
623 | { | 625 | { | |
624 | struct archive *pkg; | 626 | struct archive *pkg; | |
625 | struct archive_entry *entry, *hash_entry, *sign_entry; | 627 | struct archive_entry *entry, *hash_entry, *sign_entry; | |
626 | int fd; | 628 | int fd; | |
627 | struct stat sb; | 629 | struct stat sb; | |
628 | char *hash_file, *signature_file, *tmp, *pkgname, hash[SHA512_DIGEST_STRING_LENGTH]; | 630 | char *hash_file, *signature_file, *tmp, *pkgname, hash[SHA512_DIGEST_STRING_LENGTH]; | |
629 | unsigned char block[65536]; | 631 | unsigned char block[65536]; | |
@@ -696,15 +698,17 @@ pkg_sign_gpg(const char *name, const cha | @@ -696,15 +698,17 @@ pkg_sign_gpg(const char *name, const cha | |||
696 | if (i + sizeof(block) < size) | 698 | if (i + sizeof(block) < size) | |
697 | block_len = sizeof(block); | 699 | block_len = sizeof(block); | |
698 | else | 700 | else | |
699 | block_len = size % sizeof(block); | 701 | block_len = size % sizeof(block); | |
700 | if (read(fd, block, block_len) != block_len) | 702 | if (read(fd, block, block_len) != block_len) | |
701 | err(2, "short read"); | 703 | err(2, "short read"); | |
702 | archive_write_data(pkg, block, block_len); | 704 | archive_write_data(pkg, block, block_len); | |
703 | } | 705 | } | |
704 | archive_write_finish_entry(pkg); | 706 | archive_write_finish_entry(pkg); | |
705 | archive_entry_free(entry); | 707 | archive_entry_free(entry); | |
706 | 708 | |||
707 | archive_write_finish(pkg); | 709 | archive_write_finish(pkg); | |
708 | 710 | |||
711 | close(fd); | |||
712 | ||||
709 | exit(0); | 713 | exit(0); | |
710 | } | 714 | } |
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: version.h,v 1.115 2009/02/28 16:03:56 joerg Exp $ */ | 1 | /* $NetBSD: version.h,v 1.116 2009/03/02 14:59:14 joerg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001 Thomas Klausner. All rights reserved. | 4 | * Copyright (c) 2001 Thomas Klausner. All rights reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -17,16 +17,16 @@ | @@ -17,16 +17,16 @@ | |||
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 | */ | 25 | */ | |
26 | 26 | |||
27 | #ifndef _INST_LIB_VERSION_H_ | 27 | #ifndef _INST_LIB_VERSION_H_ | |
28 | #define _INST_LIB_VERSION_H_ | 28 | #define _INST_LIB_VERSION_H_ | |
29 | 29 | |||
30 | #define PKGTOOLS_VERSION "20090228" | 30 | #define PKGTOOLS_VERSION "20090301" | |
31 | 31 | |||
32 | #endif /* _INST_LIB_VERSION_H_ */ | 32 | #endif /* _INST_LIB_VERSION_H_ */ |
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: vulnerabilities-file.c,v 1.4 2009/02/02 12:35:01 joerg Exp $ */ | 1 | /* $NetBSD: vulnerabilities-file.c,v 1.5 2009/03/02 14:59:14 joerg Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. | 4 | * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * | 10 | * | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in | 14 | * notice, this list of conditions and the following disclaimer in | |
@@ -28,27 +28,27 @@ | @@ -28,27 +28,27 @@ | |||
28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_CONFIG_H | 32 | #if HAVE_CONFIG_H | |
33 | #include "config.h" | 33 | #include "config.h" | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <nbcompat.h> | 36 | #include <nbcompat.h> | |
37 | 37 | |||
38 | #if HAVE_SYS_CDEFS_H | 38 | #if HAVE_SYS_CDEFS_H | |
39 | #include <sys/cdefs.h> | 39 | #include <sys/cdefs.h> | |
40 | #endif | 40 | #endif | |
41 | __RCSID("$NetBSD: vulnerabilities-file.c,v 1.4 2009/02/02 12:35:01 joerg Exp $"); | 41 | __RCSID("$NetBSD: vulnerabilities-file.c,v 1.5 2009/03/02 14:59:14 joerg Exp $"); | |
42 | 42 | |||
43 | #if HAVE_SYS_STAT_H | 43 | #if HAVE_SYS_STAT_H | |
44 | #include <sys/stat.h> | 44 | #include <sys/stat.h> | |
45 | #endif | 45 | #endif | |
46 | #if HAVE_SYS_WAIT_H | 46 | #if HAVE_SYS_WAIT_H | |
47 | #include <sys/wait.h> | 47 | #include <sys/wait.h> | |
48 | #endif | 48 | #endif | |
49 | #include <ctype.h> | 49 | #include <ctype.h> | |
50 | #if HAVE_ERR_H | 50 | #if HAVE_ERR_H | |
51 | #include <err.h> | 51 | #include <err.h> | |
52 | #endif | 52 | #endif | |
53 | #include <errno.h> | 53 | #include <errno.h> | |
54 | #include <fcntl.h> | 54 | #include <fcntl.h> | |
@@ -358,26 +358,28 @@ read_pkg_vulnerabilities(const char *pat | @@ -358,26 +358,28 @@ read_pkg_vulnerabilities(const char *pat | |||
358 | errx(EXIT_FAILURE, "Input is not regular file"); | 358 | errx(EXIT_FAILURE, "Input is not regular file"); | |
359 | if (st.st_size > SSIZE_MAX - 1) | 359 | if (st.st_size > SSIZE_MAX - 1) | |
360 | errx(EXIT_FAILURE, "Input too large"); | 360 | errx(EXIT_FAILURE, "Input too large"); | |
361 | 361 | |||
362 | input_len = (size_t)st.st_size; | 362 | input_len = (size_t)st.st_size; | |
363 | if (input_len < 4) | 363 | if (input_len < 4) | |
364 | err(EXIT_FAILURE, "Input too short for a pkg_vulnerability file"); | 364 | err(EXIT_FAILURE, "Input too short for a pkg_vulnerability file"); | |
365 | input = xmalloc(input_len + 1); | 365 | input = xmalloc(input_len + 1); | |
366 | if ((bytes_read = read(fd, input, input_len)) == -1) | 366 | if ((bytes_read = read(fd, input, input_len)) == -1) | |
367 | err(1, "Failed to read input"); | 367 | err(1, "Failed to read input"); | |
368 | if (bytes_read != st.st_size) | 368 | if (bytes_read != st.st_size) | |
369 | errx(1, "Unexpected short read"); | 369 | errx(1, "Unexpected short read"); | |
370 | 370 | |||
371 | close(fd); | |||
372 | ||||
371 | if (decompress_buffer(input, input_len, &decompressed_input, | 373 | if (decompress_buffer(input, input_len, &decompressed_input, | |
372 | &decompressed_len)) { | 374 | &decompressed_len)) { | |
373 | free(input); | 375 | free(input); | |
374 | input = decompressed_input; | 376 | input = decompressed_input; | |
375 | input_len = decompressed_len; | 377 | input_len = decompressed_len; | |
376 | } | 378 | } | |
377 | pv = parse_pkg_vulnerabilities(input, input_len, check_sum); | 379 | pv = parse_pkg_vulnerabilities(input, input_len, check_sum); | |
378 | free(input); | 380 | free(input); | |
379 | 381 | |||
380 | return pv; | 382 | return pv; | |
381 | } | 383 | } | |
382 | 384 | |||
383 | struct pkg_vulnerabilities * | 385 | struct pkg_vulnerabilities * |