From cfed420cd35d7d57d4c0f704f135928c11054291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Fri, 5 Nov 2021 11:18:03 +0100 Subject: [PATCH 1/2] Add Coverity Scan to CI --- .github/workflows/coverity.yml | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/coverity.yml diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml new file mode 100644 index 0000000..eb4a41c --- /dev/null +++ b/.github/workflows/coverity.yml @@ -0,0 +1,37 @@ +name: coverity +on: [push, pull_request] + +jobs: + analyze: + if: github.repository == 'c9s/r3' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Download Coverity + run: | + cd .. + wget -q https://scan.coverity.com/download/linux64 --post-data "token=${COVERITY_TOKEN}&project=r3" -O coverity-linux64.tgz + mkdir coverity + tar xzf coverity-linux64.tgz --strip 1 -C coverity + echo "$(pwd)/coverity/bin" >> $GITHUB_PATH + env: + COVERITY_TOKEN: ${{ secrets.COVERITY_TOKEN }} + + - name: Build with Coverity + run: | + ./autogen.sh + ./configure --enable-check --enable-debug + cov-build --dir cov-int make V=1 + + - name: Submit the result to Coverity + run: | + tar czvf r3.tgz cov-int + curl \ + --form token=${COVERITY_TOKEN} \ + --form email=yoanlin93+github@gmail.com \ + --form file=@r3.tgz \ + --form version=${GITHUB_SHA} \ + https://scan.coverity.com/builds?project=r3 + env: + COVERITY_TOKEN: ${{ secrets.COVERITY_TOKEN }} From 04d52a6dd199d180196895e3d21d98c976fabeeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Mon, 8 Nov 2021 14:49:12 +0100 Subject: [PATCH 2/2] Fix Coverity warning The return value was checked on all calls to r3_slug_find_placeholder() except in one place, which triggered a Coverity warning. This adds a check (assert), and enables the other asserts for non-debug builds to catch segmentation faults early. --- src/node.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/node.c b/src/node.c index 399e672..46a70b2 100644 --- a/src/node.c +++ b/src/node.c @@ -720,18 +720,11 @@ R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int pa if ( slug_cnt > 1 ) { unsigned int slug_len; const char *p = r3_slug_find_placeholder(path, path_len, &slug_len); - -#ifdef DEBUG assert(p); -#endif // find the next one '{', then break there - if(p) { - p = r3_slug_find_placeholder(p + slug_len + 1, path_len - slug_len - 1, NULL); - } -#ifdef DEBUG + p = r3_slug_find_placeholder(p + slug_len + 1, path_len - slug_len - 1, NULL); assert(p); -#endif // insert the first one edge, and break at "p" R3Node * child = r3_tree_create(3); @@ -745,6 +738,7 @@ R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int pa // there is one slug, let's see if it's optimiz-able by opcode unsigned int slug_len = 0; const char *slug_p = r3_slug_find_placeholder(path, path_len, &slug_len); + assert(slug_p); unsigned int slug_pattern_len = 0; const char *slug_pattern = r3_slug_find_pattern(slug_p, slug_len, &slug_pattern_len);