From owner-p4-projects@FreeBSD.ORG Fri May 7 12:52:35 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2C7621065675; Fri, 7 May 2010 12:52:35 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E5094106567B for ; Fri, 7 May 2010 12:52:34 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id CAF348FC1F for ; Fri, 7 May 2010 12:52:34 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o47CqYTn007326 for ; Fri, 7 May 2010 12:52:34 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o47CqYMW007324 for perforce@freebsd.org; Fri, 7 May 2010 12:52:34 GMT (envelope-from gcooper@FreeBSD.org) Date: Fri, 7 May 2010 12:52:34 GMT Message-Id: <201005071252.o47CqYMW007324@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 177900 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 May 2010 12:52:35 -0000 http://p4web.freebsd.org/@@177900?ac=10 Change 177900 by gcooper@gcooper-bayonetta on 2010/05/07 12:51:53 1. Make code more robust by dealing with potential error cases when archive_read_new(3) fails. 2. Also, free the archive object after the read is done, if it was properly initialized. Affected files ... .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/file.c#4 edit Differences ... ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/file.c#4 (text+ko) ==== @@ -389,31 +389,38 @@ printf("%s: will extract %s from %s\n", __func__, file, pkg_name_humanized); - archive = archive_read_new(); - archive_read_support_compression_all(archive); - archive_read_support_format_tar(archive); + if ((archive = archive_read_new()) != NULL) { + + archive_read_support_compression_all(archive); + archive_read_support_format_tar(archive); + + /* + * Avoid potential race conditions with + * archive_read_open_filename(3), by opening the file + * beforehand. + */ + if (pkg == NULL) + archive_fd = fileno(stdin); + else + archive_fd = open(pkg, O_RDONLY); - /* - * Avoid potential race conditions with archive_read_open_filename(3), - * by opening the file beforehand. - */ - if (pkg == NULL) - archive_fd = fileno(stdin); - else - archive_fd = open(pkg, O_RDONLY); + } + if (archive == NULL) { + error = archive_error_string(archive); + warnx("%s: unable to open the package from %s: %s", + __func__, pkg_name_humanized, error); + } /* The initial open failed */ - if (archive_fd == -1) + else if (archive_fd == -1) warn("%s: unable to open the package from %s", __func__, pkg_name_humanized); /* archive(3) failed to open the file. */ else if (archive_read_open_fd(archive, archive_fd, ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { - error = archive_error_string(archive); warnx("%s: unable to open the package from %s: %s", __func__, pkg_name_humanized, error); - } else while (error == NULL && found_match == FALSE && @@ -452,8 +459,9 @@ } - archive_read_finish(archive); + if (archive != NULL) + archive_read_finish(archive); /* Close any open descriptors. */ if (0 <= archive_fd) close(archive_fd); @@ -499,21 +507,30 @@ pkg_name_humanized, __func__, file_expr); } - archive = archive_read_new(); - archive_read_support_compression_all(archive); - archive_read_support_format_tar(archive); + if ((archive = archive_read_new()) != NULL) { + + archive_read_support_compression_all(archive); + archive_read_support_format_tar(archive); + + /* + * Avoid potential race conditions with + * archive_read_open_filename(3), by opening the file + * beforehand. + */ + if (pkg == NULL) + archive_fd = fileno(stdin); + else + archive_fd = open(pkg, O_RDONLY); - /* - * Avoid potential race conditions with archive_read_open_filename(3), - * by opening the file beforehand. - */ - if (pkg == NULL) - archive_fd = fileno(stdin); - else - archive_fd = open(pkg, O_RDONLY); + } + if (archive == NULL) { + error = archive_error_string(archive); + warnx("%s: unable to open the package from %s: %s", + __func__, pkg_name_humanized, error); + } /* The initial open failed */ - if (archive_fd == -1) + else if (archive_fd == -1) warn("%s: unable to open the package from %s", __func__, pkg_name_humanized); else if (archive_read_open_fd(archive, archive_fd, @@ -556,8 +573,8 @@ } serrno = errno; - archive_read_finish(archive); - + if (archive != NULL) + archive_read_finish(archive); /* Close any open descriptors. */ if (0 <= archive_fd) close(archive_fd);