Skip to content

Commit ab7782c

Browse files
Merge branch 'master' into csot
2 parents 735daf6 + f1dde69 commit ab7782c

File tree

3 files changed

+99
-68
lines changed

3 files changed

+99
-68
lines changed

.evergreen/tools.rb

Lines changed: 0 additions & 67 deletions
This file was deleted.

.github/workflows/codeql.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
schedule:
9+
- cron: '20 0 * * 0'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze (${{ matrix.language }})
14+
# Runner size impacts CodeQL analysis time. To learn more, please see:
15+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
16+
# - https://gh.io/supported-runners-and-hardware-resources
17+
# - https://gh.io/using-larger-runners (GitHub.com only)
18+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
19+
runs-on: 'ubuntu-latest'
20+
timeout-minutes: 360
21+
permissions:
22+
# required for all workflows
23+
security-events: write
24+
25+
# required to fetch internal or private CodeQL packs
26+
packages: read
27+
28+
# only required for workflows in private repositories
29+
actions: read
30+
contents: read
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
include:
36+
- language: ruby
37+
build-mode: none
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
# Initializes the CodeQL tools for scanning.
43+
- name: Initialize CodeQL
44+
uses: github/codeql-action/init@v3
45+
with:
46+
languages: ${{ matrix.language }}
47+
build-mode: ${{ matrix.build-mode }}
48+
config: |
49+
paths-ignore:
50+
- .evergreen
51+
- spec
52+
# If you wish to specify custom queries, you can do so here or in a config file.
53+
# By default, queries listed here will override any specified in a config file.
54+
# Prefix the list here with "+" to use these queries and those in the config file.
55+
56+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
57+
# queries: security-extended,security-and-quality
58+
59+
# If the analyze step fails for one of the languages you are analyzing with
60+
# "We were unable to automatically build your code", modify the matrix above
61+
# to set the build mode to "manual" for that language. Then modify this step
62+
# to build your code.
63+
# ℹ️ Command-line programs to run using the OS shell.
64+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
65+
- if: matrix.build-mode == 'manual'
66+
run: |
67+
echo 'If you are using a "manual" build mode for one or more of the' \
68+
'languages you are analyzing, replace this with the commands to build' \
69+
'your code, for example:'
70+
echo ' make bootstrap'
71+
echo ' make release'
72+
exit 1
73+
74+
- name: Perform CodeQL Analysis
75+
uses: github/codeql-action/analyze@v3
76+
with:
77+
category: "/language:${{matrix.language}}"

lib/mongo/socket/ssl.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def set_cert(context, options)
379379
# for instance, if there is no newline between two certificates
380380
# this code will extract them both but OpenSSL fails in this situation.
381381
if cert_text
382-
certs = cert_text.scan(/-----BEGIN CERTIFICATE-----(?:.|\n)+?-----END CERTIFICATE-----/)
382+
certs = extract_certs(cert_text)
383383
if certs.length > 1
384384
context.cert = OpenSSL::X509::Certificate.new(certs.shift)
385385
context.extra_chain_cert = certs.map do |cert|
@@ -482,6 +482,27 @@ def run_tls_context_hooks
482482
hook.call(@context)
483483
end
484484
end
485+
486+
BEGIN_CERT = "-----BEGIN CERTIFICATE-----"
487+
END_CERT = "-----END CERTIFICATE-----"
488+
489+
# This was originally a scan + regex, but the regex was particularly
490+
# inefficient and was flagged as a concern by static analysis.
491+
def extract_certs(text)
492+
[].tap do |list|
493+
pos = 0
494+
495+
while (begin_idx = text.index(BEGIN_CERT, pos))
496+
end_idx = text.index(END_CERT, begin_idx)
497+
break unless end_idx
498+
499+
end_idx += END_CERT.length
500+
list.push(text[begin_idx...end_idx])
501+
502+
pos = end_idx
503+
end
504+
end
505+
end
485506
end
486507
end
487508
end

0 commit comments

Comments
 (0)