Skip to content

Commit

Permalink
testmmap: Avoid a crash after test_file_open() fails.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1920246 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
minfrin committed Aug 28, 2024
1 parent cf6c66b commit 44a73a5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-*- coding: utf-8 -*-
Changes for APR 2.0.0

*) testmmap: Avoid a crash after test_file_open() fails. [Graham
Leggett]

*) apr_proc_mutex_timedlock() should return APR_TIMEUP on systems
where semtimedop() returns ETIMEDOUT rather than
EAGAIN. Likely AIX-only. [Eric Covener]
Expand Down
41 changes: 39 additions & 2 deletions test/testmmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ static void test_file_close(abts_case *tc, void *data)
{
apr_status_t rv;

if (!thefile) {
ABTS_SKIP(tc, data, "File not open, skipping file close.");
return;
}

rv = apr_file_close(thefile);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
thefile = NULL;
Expand All @@ -96,6 +101,11 @@ static void test_get_filesize(abts_case *tc, void *data)
{
apr_status_t rv;

if (!thefile) {
ABTS_SKIP(tc, data, "File not open, skipping filesize test.");
return;
}

rv = apr_file_info_get(&thisfinfo, APR_FINFO_NORM, thefile);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
ABTS_TRUE(tc, thisfinfo.size == (apr_off_t)(apr_size_t)thisfinfo.size);
Expand All @@ -111,6 +121,11 @@ static void read_expected_contents(abts_case *tc, void *data)
apr_size_t nbytes = 0;
apr_status_t rv;

if (!thefile) {
ABTS_SKIP(tc, data, "File not open, skipping read.");
return;
}

ABTS_TRUE(tc, *offset == (apr_off_t)(apr_size_t)*offset);

rv = apr_file_read_full(thefile, thisfdata, thisfsize, &nbytes);
Expand All @@ -135,6 +150,11 @@ static void test_mmap_create(abts_case *tc, void *data)
apr_off_t *offset = data;
apr_status_t rv;

if (!thefile) {
ABTS_SKIP(tc, data, "File not open, skipping mmap create.");
return;
}

rv = apr_mmap_create(&themmap, thefile, *offset, thisfsize,
APR_MMAP_READ, ptest);
ABTS_PTR_NOTNULL(tc, themmap);
Expand All @@ -144,34 +164,51 @@ static void test_mmap_create(abts_case *tc, void *data)
static void test_mmap_contents(abts_case *tc, void *data)
{
ABTS_PTR_NOTNULL(tc, themmap);

if (!themmap) {
ABTS_SKIP(tc, data, "MMap not open, skipping size comparison.");
return;
}

ABTS_PTR_NOTNULL(tc, themmap->mm);
ABTS_SIZE_EQUAL(tc, thisfsize, themmap->size);

/* Must use nEquals since the string is not guaranteed to be NULL terminated */
ABTS_STR_NEQUAL(tc, themmap->mm, thisfdata, thisfsize);

}

static void test_mmap_delete(abts_case *tc, void *data)
{
apr_status_t rv;

ABTS_PTR_NOTNULL(tc, themmap);
if (!themmap) {
ABTS_SKIP(tc, data, "MMap not open, skipping mmap delete.");
return;
}

rv = apr_mmap_delete(themmap);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
themmap = NULL;

}

static void test_mmap_offset(abts_case *tc, void *data)
{
apr_status_t rv;
void *addr;

ABTS_PTR_NOTNULL(tc, themmap);
if (!themmap) {
ABTS_SKIP(tc, data, "MMap not open, skipping mmap offset.");
return;
}

rv = apr_mmap_offset(&addr, themmap, 5);

ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
/* Must use nEquals since the string is not guaranteed to be NULL terminated */
ABTS_STR_NEQUAL(tc, addr, thisfdata + 5, thisfsize - 5);

}

#endif
Expand Down

0 comments on commit 44a73a5

Please sign in to comment.