Skip to content

Commit a413325

Browse files
committed
fix(bin): reject oversized ports before arithmetic conversion
parse_port_from_url() converted the digit string with $((10#$port)) before bounding it. Bash evaluates in 64 bits and wraps silently, so an out-of-range value could re-enter 1..65535 and be accepted as a real port: 18446744073709551617 parsed as 1, and 18446744073709559616 as 8000. The preflight would then abort startup naming a port that was never configured. Normalise the leading-zero form textually instead, reject anything longer than five digits, and only then convert and range-check. Java reads 08080 as 8080, so that form is still accepted. Covers both wrapping values, an all-zero port, and a long leading-zero form in the URL-parsing table.
1 parent ea81ad7 commit a413325

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ function parse_port_from_url() {
176176
fi
177177

178178
[[ "$port" =~ ^[0-9]+$ ]] || return 1
179-
# Normalise leading-zero forms; Java reads 08080 as decimal 8080.
180-
port=$((10#$port))
179+
# Normalise leading-zero forms textually; Java reads 08080 as decimal 8080.
180+
# Arithmetic conversion must not happen before the value is bounded: Bash
181+
# evaluates in 64-bit and wraps silently, so 18446744073709559616 would
182+
# otherwise pass the range check as port 8000.
183+
port="${port#"${port%%[!0]*}"}"
184+
[[ -z "$port" ]] && return 1
185+
(( ${#port} <= 5 )) || return 1
181186
(( port >= 1 && port <= 65535 )) || return 1
182187

183188
echo "$port"

hugegraph-server/hugegraph-dist/src/assembly/travis/test-check-port.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ url_cases=(
9393
'http://127.0.0.1:0|SKIP'
9494
'http://127.0.0.1:70000|SKIP'
9595
'127.0.0.1|SKIP'
96+
# Oversized values must be rejected on their digits, not after a 64-bit
97+
# arithmetic conversion that would wrap them back into range.
98+
'http://127.0.0.1:18446744073709551617|SKIP'
99+
'http://127.0.0.1:18446744073709559616|SKIP'
100+
'http://127.0.0.1:0000000000000008080|8080'
101+
'http://127.0.0.1:00000|SKIP'
96102
)
97103
for case in "${url_cases[@]}"; do
98104
url="${case%|*}"

0 commit comments

Comments
 (0)