Deleted Added
full compact
test_write_disk_secure745.c (305188) test_write_disk_secure745.c (306321)
1/*-
2 * Copyright (c) 2003-2007,2016 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#include "test.h"
1/*-
2 * Copyright (c) 2003-2007,2016 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#include "test.h"
26__FBSDID("$FreeBSD: stable/11/contrib/libarchive/libarchive/test/test_write_disk_secure745.c 305188 2016-09-01 07:53:59Z mm $");
26__FBSDID("$FreeBSD: stable/11/contrib/libarchive/libarchive/test/test_write_disk_secure745.c 306321 2016-09-25 22:02:27Z mm $");
27
28#define UMASK 022
29
30/*
31 * Github Issue #745 describes a bug in the sandboxing code that
32 * allows one to use a symlink to edit the permissions on a file or
33 * directory outside of the sandbox.
34 */

--- 18 unchanged lines hidden (view full) ---

53
54 /* The sandbox dir we're going to run inside of. */
55 assertMakeDir("sandbox", 0700);
56 assertChdir("sandbox");
57
58 /* Create a symlink pointing to the target directory */
59 assert((ae = archive_entry_new()) != NULL);
60 archive_entry_copy_pathname(ae, "sym");
27
28#define UMASK 022
29
30/*
31 * Github Issue #745 describes a bug in the sandboxing code that
32 * allows one to use a symlink to edit the permissions on a file or
33 * directory outside of the sandbox.
34 */

--- 18 unchanged lines hidden (view full) ---

53
54 /* The sandbox dir we're going to run inside of. */
55 assertMakeDir("sandbox", 0700);
56 assertChdir("sandbox");
57
58 /* Create a symlink pointing to the target directory */
59 assert((ae = archive_entry_new()) != NULL);
60 archive_entry_copy_pathname(ae, "sym");
61 archive_entry_set_mode(ae, S_IFREG | 0777);
61 archive_entry_set_mode(ae, AE_IFLNK | 0777);
62 archive_entry_copy_symlink(ae, "../target");
63 assert(0 == archive_write_header(a, ae));
64 archive_entry_free(ae);
65
66 /* Try to alter the target dir through the symlink; this should fail. */
67 assert((ae = archive_entry_new()) != NULL);
68 archive_entry_copy_pathname(ae, "sym");
69 archive_entry_set_mode(ae, S_IFDIR | 0777);
70 assert(0 == archive_write_header(a, ae));
71 archive_entry_free(ae);
72
73 /* Permission of target dir should not have changed. */
74 assertFileMode("../target", 0700);
62 archive_entry_copy_symlink(ae, "../target");
63 assert(0 == archive_write_header(a, ae));
64 archive_entry_free(ae);
65
66 /* Try to alter the target dir through the symlink; this should fail. */
67 assert((ae = archive_entry_new()) != NULL);
68 archive_entry_copy_pathname(ae, "sym");
69 archive_entry_set_mode(ae, S_IFDIR | 0777);
70 assert(0 == archive_write_header(a, ae));
71 archive_entry_free(ae);
72
73 /* Permission of target dir should not have changed. */
74 assertFileMode("../target", 0700);
75
76 assert(0 == archive_write_close(a));
77 archive_write_free(a);
75#endif
76}
78#endif
79}