diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index e818685..be200da 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,10 +16,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Arduino Lint - uses: arduino/arduino-lint-action@v2 + uses: arduino/arduino-lint-action@v3 with: compliance: specification library-manager: update diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 0dd5ac7..005d046 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -38,7 +38,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Compile examples uses: arduino/compile-sketches@v1 @@ -56,7 +56,7 @@ jobs: sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - name: Save sketches report as workflow artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index ef7d894..8717032 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 53a9f54..83615bc 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Download JSON schema for labels configuration file id: download-schema @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: path: | *.yaml @@ -105,16 +105,16 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Download configuration files artifact - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v8 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v5 + uses: geekyeggo/delete-artifact@v6 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} diff --git a/src/WebSocketClient.cpp b/src/WebSocketClient.cpp index ab41b0a..443e140 100644 --- a/src/WebSocketClient.cpp +++ b/src/WebSocketClient.cpp @@ -167,7 +167,7 @@ size_t WebSocketClient::write(const uint8_t *aBuffer, size_t aSize) // check if the write size, fits in the buffer if ((iTxSize + aSize) > sizeof(iTxBuffer)) { - aSize = sizeof(iTxSize) - iTxSize; + aSize = sizeof(iTxBuffer) - iTxSize; } // copy data into the buffer @@ -206,25 +206,54 @@ int WebSocketClient::parseMessage() iRxMasked = (length & 0x80); length &= 0x7f; - // read the RX size - if (length < 126) + // work out how many extended length and mask bytes follow the + // initial opcode + length bytes + int extendedLength = 0; + if (length == 126) { - iRxSize = length; + extendedLength = 2; } - else if (length == 126) + else if (length == 127) { - iRxSize = (HttpClient::read() << 8) | HttpClient::read(); + extendedLength = 8; } - else + int maskLength = iRxMasked ? (int)sizeof(iRxMaskKey) : 0; + + // make sure the remaining header bytes are available before reading + // them, otherwise the frame header is incomplete + if (HttpClient::available() < (extendedLength + maskLength)) + { + return 0; + } + + // read the RX size + iRxSize = length; + if (length == 126) + { + // read each byte in a well-defined order (the evaluation order of + // multiple read() calls in a single expression is unspecified) + uint8_t b1 = HttpClient::read(); + uint8_t b0 = HttpClient::read(); + iRxSize = ((uint64_t)b1 << 8) | b0; + } + else if (length == 127) { - iRxSize = ((uint64_t)HttpClient::read() << 56) | - ((uint64_t)HttpClient::read() << 48) | - ((uint64_t)HttpClient::read() << 40) | - ((uint64_t)HttpClient::read() << 32) | - ((uint64_t)HttpClient::read() << 24) | - ((uint64_t)HttpClient::read() << 16) | - ((uint64_t)HttpClient::read() << 8) | - (uint64_t)HttpClient::read(); + uint8_t b7 = HttpClient::read(); + uint8_t b6 = HttpClient::read(); + uint8_t b5 = HttpClient::read(); + uint8_t b4 = HttpClient::read(); + uint8_t b3 = HttpClient::read(); + uint8_t b2 = HttpClient::read(); + uint8_t b1 = HttpClient::read(); + uint8_t b0 = HttpClient::read(); + iRxSize = ((uint64_t)b7 << 56) | + ((uint64_t)b6 << 48) | + ((uint64_t)b5 << 40) | + ((uint64_t)b4 << 32) | + ((uint64_t)b3 << 24) | + ((uint64_t)b2 << 16) | + ((uint64_t)b1 << 8) | + (uint64_t)b0; } // read in the mask, if present