Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue 140: Calling archive_read_close() twice causes problems.

SVN-Revision: 2996
  • Loading branch information...
commit 34fe1abb1a17f980a9bd93220d284c5eaaca26c9 1 parent c91b353
@kientzle kientzle authored
View
3  Makefile.am
@@ -245,6 +245,9 @@ libarchive_test_SOURCES= \
libarchive/test/test_acl_posix1e.c \
libarchive/test/test_archive_api_feature.c \
libarchive/test/test_archive_clear_error.c \
+ libarchive/test/test_archive_read_close_twice.c \
+ libarchive/test/test_archive_read_close_twice_open_fd.c \
+ libarchive/test/test_archive_read_close_twice_open_filename.c \
libarchive/test/test_archive_set_error.c \
libarchive/test/test_bad_fd.c \
libarchive/test/test_compat_bzip2.c \
View
6 libarchive/archive_read.c
@@ -305,7 +305,6 @@ client_close_proxy(struct archive_read_filter *self)
if (self->archive->client.closer != NULL)
r = (self->archive->client.closer)((struct archive *)self->archive,
self->data);
- self->data = NULL;
return (r);
}
@@ -795,9 +794,10 @@ _archive_read_close(struct archive *_a)
archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_close");
+ if (a->archive.state == ARCHIVE_STATE_CLOSED)
+ return (ARCHIVE_OK);
archive_clear_error(&a->archive);
- if (a->archive.state != ARCHIVE_STATE_FATAL)
- a->archive.state = ARCHIVE_STATE_CLOSED;
+ a->archive.state = ARCHIVE_STATE_CLOSED;
/* TODO: Clean up the formatters. */
View
3  libarchive/test/CMakeLists.txt
@@ -14,6 +14,9 @@ IF(ENABLE_TEST)
test_acl_posix1e.c
test_archive_api_feature.c
test_archive_clear_error.c
+ test_archive_read_close_twice.c
+ test_archive_read_close_twice_open_fd.c
+ test_archive_read_close_twice_open_filename.c
test_archive_set_error.c
test_bad_fd.c
test_compat_bzip2.c
View
43 libarchive/test/test_archive_read_close_twice.c
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+
+DEFINE_TEST(test_archive_read_close_twice)
+{
+ struct archive* a = archive_read_new();
+
+ assertEqualInt(0, archive_read_close(a));
+ assertEqualInt(0, archive_errno(a));
+ assertEqualString(NULL, archive_error_string(a));
+
+ assertEqualInt(0, archive_read_close(a));
+ assertEqualInt(0, archive_errno(a));
+ assertEqualString(NULL, archive_error_string(a));
+
+ archive_read_finish(a);
+}
View
53 libarchive/test/test_archive_read_close_twice_open_fd.c
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 2011 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+DEFINE_TEST(test_archive_read_close_twice_open_fd)
+{
+ struct archive* a = archive_read_new();
+
+ assertEqualInt(0, archive_read_open_fd(a, 0, 0));
+ assertEqualInt(0, archive_errno(a));
+ assertEqualString(NULL, archive_error_string(a));
+
+ assertEqualInt(0, archive_read_close(a));
+ assertEqualInt(0, archive_errno(a));
+ assertEqualString(NULL, archive_error_string(a));
+
+ assertEqualInt(0, archive_read_close(a));
+ assertEqualInt(0, archive_errno(a));
+ assertEqualString(NULL, archive_error_string(a));
+
+ archive_read_finish(a);
+}
View
53 libarchive/test/test_archive_read_close_twice_open_filename.c
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 2011 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+DEFINE_TEST(test_archive_read_close_twice_open_filename)
+{
+ struct archive* a = archive_read_new();
+
+ assertEqualInt(0, archive_read_open_filename(a, 0, 0));
+ assertEqualInt(0, archive_errno(a));
+ assertEqualString(NULL, archive_error_string(a));
+
+ assertEqualInt(0, archive_read_close(a));
+ assertEqualInt(0, archive_errno(a));
+ assertEqualString(NULL, archive_error_string(a));
+
+ assertEqualInt(0, archive_read_close(a));
+ assertEqualInt(0, archive_errno(a));
+ assertEqualString(NULL, archive_error_string(a));
+
+ archive_read_finish(a);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.