1248590Smm/*- 2248590Smm * Copyright (c) 2012 Michihiro NAKAJIMA 3248590Smm * All rights reserved. 4248590Smm * 5248590Smm * Redistribution and use in source and binary forms, with or without 6248590Smm * modification, are permitted provided that the following conditions 7248590Smm * are met: 8248590Smm * 1. Redistributions of source code must retain the above copyright 9248590Smm * notice, this list of conditions and the following disclaimer 10248590Smm * in this position and unchanged. 11248590Smm * 2. Redistributions in binary form must reproduce the above copyright 12248590Smm * notice, this list of conditions and the following disclaimer in the 13248590Smm * documentation and/or other materials provided with the distribution. 14248590Smm * 15248590Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16248590Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17248590Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18248590Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19248590Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20248590Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21248590Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22248590Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23248590Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24248590Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25248590Smm */ 26248590Smm 27248590Smm#include "test.h" 28248590Smm__FBSDID("$FreeBSD$"); 29248590Smm 30248590Smmstatic char buff[4096]; 31248590Smm 32248590Smmstatic const char image [] = { 33248590Smm"#mtree\n" 34248590Smm"./a\\040!$\\043&\\075_^z\\177~ mode=644 type=file\n" 35248590Smm}; 36248590Smm 37248590Smm 38248590SmmDEFINE_TEST(test_write_format_mtree_quoted_filename) 39248590Smm{ 40248590Smm struct archive_entry *ae; 41248590Smm struct archive* a; 42248590Smm size_t used; 43248590Smm 44248590Smm /* Create a mtree format archive. */ 45248590Smm assert((a = archive_write_new()) != NULL); 46248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_mtree(a)); 47248590Smm assertEqualIntA(a, ARCHIVE_OK, 48248590Smm archive_write_set_format_option(a, NULL, "all", NULL)); 49248590Smm assertEqualIntA(a, ARCHIVE_OK, 50248590Smm archive_write_set_format_option(a, NULL, "type", "1")); 51248590Smm assertEqualIntA(a, ARCHIVE_OK, 52248590Smm archive_write_set_format_option(a, NULL, "mode", "1")); 53248590Smm assertEqualIntA(a, ARCHIVE_OK, 54248590Smm archive_write_open_memory(a, buff, sizeof(buff)-1, &used)); 55248590Smm 56248590Smm /* Write entry which has #, = , \ and DEL(0177) in the filename. */ 57248590Smm assert((ae = archive_entry_new()) != NULL); 58248590Smm archive_entry_set_mode(ae, AE_IFREG | 0644); 59248590Smm assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae)); 60248590Smm archive_entry_copy_pathname(ae, "./a !$#&=_^z\177~"); 61248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); 62248590Smm archive_entry_free(ae); 63248590Smm 64248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); 65248590Smm assertEqualInt(ARCHIVE_OK, archive_write_free(a)); 66248590Smm 67248590Smm buff[used] = '\0'; 68248590Smm failure("#, = and \\ in the filename should be quoted"); 69248590Smm assertEqualString(buff, image); 70248590Smm 71248590Smm /* 72248590Smm * Read the data and check it. 73248590Smm */ 74248590Smm assert((a = archive_read_new()) != NULL); 75248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 76248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 77248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); 78248590Smm 79248590Smm /* Read entry */ 80248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 81248590Smm assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae)); 82248590Smm assertEqualString("./a !$#&=_^z\177~", archive_entry_pathname(ae)); 83248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 84248590Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 85248590Smm} 86248590Smm 87