From ded0cccd8b4d189ef87845a6acef82eeaeda7244 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Wed, 21 Aug 2024 18:24:34 -0500 Subject: [PATCH 1/2] fix: catch all curl_slist_append failures There was a place were the curl_slist_append failure was not caught. --- src/util.c | 2 +- src/util.h | 8 ++++++++ src/worker.c | 15 ++++++--------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/util.c b/src/util.c index 8bcd5ca..3e90948 100644 --- a/src/util.c +++ b/src/util.c @@ -80,7 +80,7 @@ struct curl_slist *pg_text_array_to_slist(ArrayType *array, } hdr = TextDatumGetCString(value); - headers = curl_slist_append(headers, hdr); + CURL_SLIST_APPEND(headers, hdr); pfree(hdr); } array_free_iterator(iterator); diff --git a/src/util.h b/src/util.h index 90ff969..6f50d29 100644 --- a/src/util.h +++ b/src/util.h @@ -13,6 +13,14 @@ ereport(ERROR, errmsg("Could not curl_easy_getinfo(%s)", #opt)); \ } while (0) +#define CURL_SLIST_APPEND(list, str) \ + do { \ + struct curl_slist *new_list = curl_slist_append(list, str); \ + if (new_list == NULL) \ + ereport(ERROR, errmsg("curl_slist_append returned NULL")); \ + list = new_list; \ + } while (0) + #define EREPORT_NULL_ATTR(tupIsNull, attr) \ do { \ if (tupIsNull) \ diff --git a/src/worker.c b/src/worker.c index 4f4b68a..05bc769 100644 --- a/src/worker.c +++ b/src/worker.c @@ -203,7 +203,6 @@ static void init_curl_handle(CURLM *curl_mhandle, CurlData *cdata, char *url, ch ereport(ERROR, errmsg("curl_multi_add_handle returned %s", curl_multi_strerror(code))); } - static void consume_request_queue(CURLM *curl_mhandle){ int ret_code = SPI_execute_with_args("\ WITH\ @@ -245,28 +244,26 @@ static void consume_request_queue(CURLM *curl_mhandle){ CurlData *cdata = palloc(sizeof(CurlData)); - struct curl_slist *request_headers = NULL; Datum headersBin = SPI_getbinval(SPI_tuptable->vals[j], SPI_tuptable->tupdesc, 5, &tupIsNull); if (!tupIsNull) { ArrayType *pgHeaders = DatumGetArrayTypeP(headersBin); + struct curl_slist *request_headers = NULL; + request_headers = pg_text_array_to_slist(pgHeaders, request_headers); + + CURL_SLIST_APPEND(request_headers, "User-Agent: pg_net/" EXTVERSION); + + cdata->request_headers = request_headers; } char *reqBody = NULL; Datum bodyBin = SPI_getbinval(SPI_tuptable->vals[j], SPI_tuptable->tupdesc, 6, &tupIsNull); if (!tupIsNull) reqBody = TextDatumGetCString(bodyBin); - cdata->body = makeStringInfo(); cdata->id = id; - struct curl_slist *new_headers = curl_slist_append(request_headers, "User-Agent: pg_net/" EXTVERSION); - if(new_headers == NULL) - ereport(ERROR, errmsg("curl_slist_append returned NULL")); - - cdata->request_headers = new_headers; - init_curl_handle(curl_mhandle, cdata, url, reqBody, method, timeout_milliseconds); } } From b839e83fa479bc3e41ba1c09986893a2dcc7590b Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Wed, 21 Aug 2024 18:33:15 -0500 Subject: [PATCH 2/2] chore: remove release.yml We'll no longer do releases for ubuntu as we'll deploy new versions using Nix. --- .github/workflows/release.yml | 116 ---------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 38ed680..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,116 +0,0 @@ -name: Release - -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - -permissions: - contents: write - -jobs: - release: - name: Create Release - runs-on: ubuntu-latest - outputs: - upload_url: ${{ steps.create-release.outputs.upload_url }} - steps: - - uses: actions/checkout@v3 - - - uses: softprops/action-gh-release@v1 - id: create-release - with: - generate_release_notes: true - - build-linux-gnu: - name: release artifacts - needs: - - release - strategy: - matrix: - extension_name: - - pg_net - # dpkg doesn't like `_` in package names - package_name: - - pg-net - postgres: [12, 13, 14, 15, 16] - box: - - { runner: ubuntu-20.04, arch: amd64 } - - { runner: arm-runner, arch: arm64 } - runs-on: ${{ matrix.box.runner }} - steps: - - uses: actions/checkout@v3 - - - name: build release artifacts - run: | - # Add postgres package repo - sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' - wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null - - sudo apt-get update - - # Install requested postgres version - sudo apt-get install -y --no-install-recommends postgresql-${{ matrix.postgres }} postgresql-server-dev-${{ matrix.postgres }} - - # Ensure installed pg_config is first on path - export PATH="/usr/lib/postgresql/${{ matrix.postgres }}/bin:$PATH" - - # Install pg_net dependencies - sudo apt-get install -y --no-install-recommends libcurl4-gnutls-dev - - # Build pg_net - make - - # name of the package directory before packaging - package_dir=${{ matrix.extension_name }}-${{ github.ref_name }}-pg${{ matrix.postgres }}-${{ matrix.box.arch }}-linux-gnu - - # Copy files into directory structure - mkdir -p ${package_dir}/usr/lib/postgresql/lib - mkdir -p ${package_dir}/var/lib/postgresql/extension - cp *.so ${package_dir}/usr/lib/postgresql/lib - cp *.control ${package_dir}/var/lib/postgresql/extension - cp sql/*.sql ${package_dir}/var/lib/postgresql/extension - - # symlinks to Copy files into directory structure - mkdir -p ${package_dir}/usr/lib/postgresql/${{ matrix.postgres }}/lib - cd ${package_dir}/usr/lib/postgresql/${{ matrix.postgres }}/lib - cp -s ../../lib/*.so . - cd ../../../../../.. - - mkdir -p ${package_dir}/usr/share/postgresql/${{ matrix.postgres }}/extension - cd ${package_dir}/usr/share/postgresql/${{ matrix.postgres }}/extension - cp -s ../../../../../var/lib/postgresql/extension/${{ matrix.extension_name }}.control . - cp -s ../../../../../var/lib/postgresql/extension/${{ matrix.extension_name }}*.sql . - cd ../../../../../.. - - # Create install control file - extension_version=${{ github.ref_name }} - # strip the leading v - deb_version=${extension_version:1} - - mkdir -p ${package_dir}/DEBIAN - touch ${package_dir}/DEBIAN/control - echo 'Package: ${{ matrix.package_name }}' >> ${package_dir}/DEBIAN/control - echo 'Version:' ${deb_version} >> ${package_dir}/DEBIAN/control - echo 'Architecture: ${{ matrix.box.arch }}' >> ${package_dir}/DEBIAN/control - echo 'Maintainer: supabase' >> ${package_dir}/DEBIAN/control - echo 'Description: A PostgreSQL extension' >> ${package_dir}/DEBIAN/control - - # Create deb package - sudo chown -R root:root ${package_dir} - sudo chmod -R 00755 ${package_dir} - sudo dpkg-deb --build --root-owner-group ${package_dir} - - - name: Get upload url - run: echo UPLOAD_URL=$(curl --silent https://api.github.com/repos/${{ github.repository }}/releases/latest | jq .upload_url --raw-output) >> $GITHUB_ENV - - - name: Upload release asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.release.outputs.upload_url }} - asset_path: ./${{ matrix.extension_name }}-${{ github.ref_name }}-pg${{ matrix.postgres }}-${{ matrix.box.arch }}-linux-gnu.deb - asset_name: ${{ matrix.extension_name }}-${{ github.ref_name }}-pg${{ matrix.postgres }}-${{ matrix.box.arch }}-linux-gnu.deb - asset_content_type: application/vnd.debian.binary-package