~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to tests/kernel/mmap-dir/test.c

  • Committer: Dustin Kirkland
  • Date: 2009-02-13 15:57:24 UTC
  • Revision ID: kirkland@canonical.com-20090213155724-1q3qz2o0cbyimu9x
debian/ubuntu packaging

Initial checkin of the Debian/Ubuntu packaging

Signed-off-by: Dustin Kirkland <kirkland@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Author: Colin King <colin.king@canonical.com>
3
 
 *
4
 
 * Copyright (C) 2012 Canonical, Ltd.
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU General Public License
8
 
 * as published by the Free Software Foundation; either version 2
9
 
 * of the License, or (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19
 
 */
20
 
 
21
 
#include <unistd.h>
22
 
#include <stdio.h>
23
 
#include <stdlib.h>
24
 
#include <string.h>
25
 
#include <errno.h>
26
 
#include <fcntl.h>
27
 
#include <sys/mman.h>
28
 
#include <sys/types.h>
29
 
#include <sys/stat.h>
30
 
#include <limits.h>
31
 
 
32
 
#define TEST_PASSED     (0)
33
 
#define TEST_FAILED     (1)
34
 
#define TEST_ERROR      (2)
35
 
 
36
 
#define MMAP_LEN        (4096)
37
 
 
38
 
/*
39
 
 *  https://bugs.launchpad.net/ecryptfs/+bug/400443
40
 
 *
41
 
 *  mmap() on a directory should return -ENODEV, but bug LP: #400443
42
 
 *  ecryptfs returns a mmap'd address which causes SIGBUS on access.
43
 
 */
44
 
int main(int argc, char **argv)
45
 
{
46
 
        int fd;
47
 
        unsigned int *ptr;
48
 
        char path[PATH_MAX];
49
 
 
50
 
        if (argc < 2) {
51
 
                fprintf(stderr, "Usage: path\n");
52
 
                exit(TEST_ERROR);
53
 
        }
54
 
        snprintf(path, sizeof(path), "%s/.", argv[1]);
55
 
 
56
 
        if ((fd = open(path, O_RDONLY)) < 0) {
57
 
                fprintf(stderr, "Cannot open ./. : %s\n", strerror(errno));
58
 
                exit(TEST_ERROR);
59
 
        }
60
 
 
61
 
        ptr = mmap(NULL, MMAP_LEN, PROT_READ, MAP_PRIVATE, fd, 0);
62
 
        close(fd);
63
 
 
64
 
        if (ptr != MAP_FAILED) {
65
 
                /* Should not be able to mmap onto a directory */
66
 
                fprintf(stderr, "mmap() on a directory should produce return "
67
 
                        "MAP_FAILED, instead got %p\n", ptr);
68
 
                munmap(ptr, MMAP_LEN);
69
 
                exit(TEST_FAILED);
70
 
        }
71
 
 
72
 
        if (errno != ENODEV) {
73
 
                fprintf(stderr, "mmap() on a directory should return ENODEV, "
74
 
                        "instead got %d (%s)\n", errno, strerror(errno));
75
 
                exit(TEST_FAILED);
76
 
        }
77
 
 
78
 
        exit(TEST_PASSED);
79
 
}