You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2022/02/14 15:33:44 UTC
svn commit: r1898076 - in /apr/apr/trunk: .travis.yml poll/unix/poll.c random/unix/apr_random.c tables/apr_skiplist.c test/teststr.c
Author: jorton
Date: Mon Feb 14 15:33:44 2022
New Revision: 1898076
URL: http://svn.apache.org/viewvc?rev=1898076&view=rev
Log:
Fix various harmless cases of undefined behaviour, and add a Travis
job testing under UBSan.
* poll/unix/poll.c (apr_poll): For the on-stack array allocation use
num+1 since allocating a 0-length array is undefined behaviour.
* tables/apr_skiplist.c (get_b_rand): Use unsigned integers to avoid
signed integer overflow in the left shift.
(skiplist_qpush): Avoid calling memcpy(,NULL,0).
* random/unix/apr_random.c (apr_random_add_entropy): Avoid calling
memcpy(,NULL,0).
* test/teststr.c (overflow_strfsize): Avoid signed integer overflow.
Modified:
apr/apr/trunk/.travis.yml
apr/apr/trunk/poll/unix/poll.c
apr/apr/trunk/random/unix/apr_random.c
apr/apr/trunk/tables/apr_skiplist.c
apr/apr/trunk/test/teststr.c
Modified: apr/apr/trunk/.travis.yml
URL: http://svn.apache.org/viewvc/apr/apr/trunk/.travis.yml?rev=1898076&r1=1898075&r2=1898076&view=diff
==============================================================================
--- apr/apr/trunk/.travis.yml (original)
+++ apr/apr/trunk/.travis.yml Mon Feb 14 15:33:44 2022
@@ -70,6 +70,17 @@ matrix:
packages:
- libtool-bin
- gcc-10
+ - name: GCC-10, UBsan (Focal)
+ dist: focal
+ env: CC=gcc-10
+ NOTEST_CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer -Werror -O2"
+ addons:
+ apt:
+ sources:
+ - sourceline: 'ppa:ubuntu-toolchain-r/test'
+ packages:
+ - libtool-bin
+ - gcc-10
before_script: sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
Modified: apr/apr/trunk/poll/unix/poll.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/poll.c?rev=1898076&r1=1898075&r2=1898076&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/poll.c (original)
+++ apr/apr/trunk/poll/unix/poll.c Mon Feb 14 15:33:44 2022
@@ -75,7 +75,7 @@ APR_DECLARE(apr_status_t) apr_poll(apr_p
int i, num_to_poll;
#ifdef HAVE_VLA
/* XXX: I trust that this is a segv when insufficient stack exists? */
- struct pollfd pollset[num];
+ struct pollfd pollset[num + 1]; /* +1 since allocating 0 is undefined behaviour */
#elif defined(HAVE_ALLOCA)
struct pollfd *pollset = alloca(sizeof(struct pollfd) * num);
if (!pollset)
Modified: apr/apr/trunk/random/unix/apr_random.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/random/unix/apr_random.c?rev=1898076&r1=1898075&r2=1898076&view=diff
==============================================================================
--- apr/apr/trunk/random/unix/apr_random.c (original)
+++ apr/apr/trunk/random/unix/apr_random.c Mon Feb 14 15:33:44 2022
@@ -238,7 +238,7 @@ APR_DECLARE(void) apr_random_add_entropy
if (p->pool_size < p->bytes+1) {
unsigned char *np = apr_palloc(g->apr_pool,(p->bytes+1)*2);
- memcpy(np,p->pool,p->bytes);
+ if (p->pool) memcpy(np,p->pool,p->bytes);
p->pool = np;
p->pool_size = (p->bytes+1)*2;
}
Modified: apr/apr/trunk/tables/apr_skiplist.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/tables/apr_skiplist.c?rev=1898076&r1=1898075&r2=1898076&view=diff
==============================================================================
--- apr/apr/trunk/tables/apr_skiplist.c (original)
+++ apr/apr/trunk/tables/apr_skiplist.c Mon Feb 14 15:33:44 2022
@@ -60,15 +60,15 @@ struct apr_skiplistnode {
apr_skiplist *sl;
};
-static int get_b_rand(void)
+static unsigned int get_b_rand(void)
{
- static int ph = 32; /* More bits than we will ever use */
- static int randseq;
+ static unsigned int ph = 32; /* More bits than we will ever use */
+ static unsigned int randseq;
if (ph > 31) { /* Num bits in return of rand() */
ph = 0;
randseq = rand();
}
- return randseq & (1 << ph++);
+ return randseq & (1U << ph++);
}
typedef struct {
@@ -159,7 +159,7 @@ static apr_status_t skiplist_qpush(apr_s
size_t size = (q->pos) ? q->pos * 2 : 32;
if (q->p) {
data = apr_palloc(q->p, size * sizeof(*data));
- if (data) {
+ if (data && q->data) {
memcpy(data, q->data, q->pos * sizeof(*data));
}
}
Modified: apr/apr/trunk/test/teststr.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/teststr.c?rev=1898076&r1=1898075&r2=1898076&view=diff
==============================================================================
--- apr/apr/trunk/test/teststr.c (original)
+++ apr/apr/trunk/test/teststr.c Mon Feb 14 15:33:44 2022
@@ -309,7 +309,8 @@ static void overflow_strfsize(abts_case
}
for (off = LONG_MAX; off > 1; off /= 2) {
apr_strfsize(off, buf);
- apr_strfsize(off + 1, buf);
+ if (sizeof(apr_off_t) > sizeof(long) || off < LONG_MAX)
+ apr_strfsize(off + 1, buf);
apr_strfsize(off - 1, buf);
}