diff options
author | Joe Orton <jorton@apache.org> | 2022-02-14 15:33:44 +0000 |
---|---|---|
committer | Joe Orton <jorton@apache.org> | 2022-02-14 15:33:44 +0000 |
commit | 7bf2b07d1170ccfe0643b49b4d115d5ca5418c17 (patch) | |
tree | 19dd6099b154022436c5d80a1ac209f0ce5a5654 /tables | |
parent | 9bd2e5b1154f6446c713fbc457d41c1e6c9089e6 (diff) | |
download | apr-7bf2b07d1170ccfe0643b49b4d115d5ca5418c17.tar.gz |
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.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1898076 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tables')
-rw-r--r-- | tables/apr_skiplist.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/tables/apr_skiplist.c b/tables/apr_skiplist.c index b11acad69..8013ed781 100644 --- a/tables/apr_skiplist.c +++ b/tables/apr_skiplist.c @@ -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_skiplist_q *q, apr_skiplistnode *m) 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)); } } |