summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2021-07-02 10:43:55 +0000
committerjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2021-07-02 10:43:55 +0000
commit22a2cadcde6f5165c252725eb50bcf4144fbbb55 (patch)
tree6c34829e775faa5637846ac2f36d838178748fe2
parent70a3095969ad60891851c694b0765a85cc9b8d9a (diff)
downloadlibapr-22a2cadcde6f5165c252725eb50bcf4144fbbb55.tar.gz
Merge r1878340, r1878343, r1878354, r1878365, r1878342 from trunk:
* memory/unix/apr_pools.c (apr_pvsprintf): Fix a clang warning, the 'active' variable is never read/used before being set again to pool->active on line 1436. * file_io/unix/readwrite.c (apr_file_write, apr_file_writev): Fix Coverity warnings from ignored lseek() return value in ->buffered handling. * test/teststr.c: Add trivial testcases for apr_pstrcat (though this does not reproduce any problems from the bug). Revert non-test part of r1878354, the Coverity warning was a false -ve and there was no functional change nor bug. * locks/unix/proc_mutex.c (apr_proc_mutex_defname): Fix clang warning, remove unused local variable. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1891196 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES3
-rw-r--r--file_io/unix/readwrite.c16
-rw-r--r--locks/unix/proc_mutex.c5
-rw-r--r--memory/unix/apr_pools.c2
-rw-r--r--test/teststr.c14
5 files changed, 30 insertions, 10 deletions
diff --git a/CHANGES b/CHANGES
index 53df1a38c..6aac4c0d1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
-*- coding: utf-8 -*-
Changes for APR 1.7.1
+ *) Add error handling for lseek() failures in apr_file_write() and
+ apr_file_writev(). [Joe Orton]
+
*) Align apr_mmap()ing offset to a page boundary. PR 65158. [Yann Ylavic]
*) Don't silently set APR_FOPEN_NOCLEANUP for apr_file_mktemp() created file
diff --git a/file_io/unix/readwrite.c b/file_io/unix/readwrite.c
index ee204ab45..866acb8fa 100644
--- a/file_io/unix/readwrite.c
+++ b/file_io/unix/readwrite.c
@@ -146,7 +146,7 @@ APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size
APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, apr_size_t *nbytes)
{
- apr_size_t rv;
+ apr_size_t rv = APR_SUCCESS;
if (thefile->buffered) {
char *pos = (char *)buf;
@@ -160,13 +160,14 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a
* logically reading from
*/
apr_int64_t offset = thefile->filePtr - thefile->dataRead + thefile->bufpos;
- if (offset != thefile->filePtr)
- lseek(thefile->filedes, offset, SEEK_SET);
+ if (offset != thefile->filePtr) {
+ thefile->filePtr = lseek(thefile->filedes, offset, SEEK_SET);
+ if (thefile->filePtr == -1) rv = errno;
+ }
thefile->bufpos = thefile->dataRead = 0;
thefile->direction = 1;
}
- rv = 0;
while (rv == 0 && size > 0) {
if (thefile->bufpos == thefile->bufsize) /* write buffer is full*/
rv = apr_file_flush_locked(thefile);
@@ -244,12 +245,15 @@ APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iove
*/
apr_int64_t offset = thefile->filePtr - thefile->dataRead +
thefile->bufpos;
- if (offset != thefile->filePtr)
- lseek(thefile->filedes, offset, SEEK_SET);
+ if (offset != thefile->filePtr) {
+ thefile->filePtr = lseek(thefile->filedes, offset, SEEK_SET);
+ if (thefile->filePtr == -1) rv = errno;
+ }
thefile->bufpos = thefile->dataRead = 0;
}
file_unlock(thefile);
+ if (rv) return rv;
}
if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) {
diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c
index 8e2187ff7..ef08f9341 100644
--- a/locks/unix/proc_mutex.c
+++ b/locks/unix/proc_mutex.c
@@ -1518,11 +1518,10 @@ static apr_status_t proc_mutex_choose_method(apr_proc_mutex_t *new_mutex,
APR_DECLARE(const char *) apr_proc_mutex_defname(void)
{
- apr_status_t rv;
apr_proc_mutex_t mutex;
- if ((rv = proc_mutex_choose_method(&mutex, APR_LOCK_DEFAULT,
- NULL)) != APR_SUCCESS) {
+ if (proc_mutex_choose_method(&mutex, APR_LOCK_DEFAULT,
+ NULL) != APR_SUCCESS) {
return "unknown";
}
diff --git a/memory/unix/apr_pools.c b/memory/unix/apr_pools.c
index 50badc4b0..27d0d528a 100644
--- a/memory/unix/apr_pools.c
+++ b/memory/unix/apr_pools.c
@@ -1338,7 +1338,7 @@ APR_DECLARE(char *) apr_pvsprintf(apr_pool_t *pool, const char *fmt, va_list ap)
apr_size_t free_index;
pool_concurrency_set_used(pool);
- ps.node = active = pool->active;
+ ps.node = pool->active;
ps.pool = pool;
ps.vbuff.curpos = ps.node->first_avail;
diff --git a/test/teststr.c b/test/teststr.c
index 951a83001..1a1d8fa01 100644
--- a/test/teststr.c
+++ b/test/teststr.c
@@ -394,6 +394,19 @@ static void skip_prefix(abts_case *tc, void *data)
ABTS_STR_EQUAL(tc, apr_cstr_skip_prefix("", "12"), NULL);
}
+static void pstrcat(abts_case *tc, void *data)
+{
+ ABTS_STR_EQUAL(tc, apr_pstrcat(p, "a", "bc", "def", NULL),
+ "abcdef");
+ ABTS_STR_EQUAL(tc, apr_pstrcat(p, NULL), "");
+ ABTS_STR_EQUAL(tc, apr_pstrcat(p,
+ "a", "b", "c", "d", "e",
+ "f", "g", "h", "i", "j",
+ "1", "2", "3", "4", "5",
+ NULL),
+ "abcdefghij12345");
+}
+
abts_suite *teststr(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -412,6 +425,7 @@ abts_suite *teststr(abts_suite *suite)
abts_run_test(suite, string_cpystrn, NULL);
abts_run_test(suite, snprintf_overflow, NULL);
abts_run_test(suite, skip_prefix, NULL);
+ abts_run_test(suite, pstrcat, NULL);
return suite;
}