Commit 25c139b6

25c139b6f26cMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Merge pull request #1499 from rubys/fix-expand-path-length

File.expand_path: record the normalized length, not the reserved capacity

Details

Commit
25c139b6f26c
Parent
4d8424e97395
Merge parent
753ee8739c05

lib/sp_runtime.hmodifiedView file

@@ -5523,6 +5523,12 @@
55235523 p = q;
55245524 }
55255525 out[olen] = 0;
5526+ /* The result was sized to the pre-normalized rawlen+1 (a safe capacity
5527+ bound), but normalization can shrink it, so the actual content is olen
5528+ bytes. Record olen as the length; otherwise the string carries trailing
5529+ NUL/garbage bytes past the path (e.g. File.expand_path("x") returns a
5530+ string whose byte length includes a stray "\0"). */
5531+ sp_str_set_len(out, olen);
55265532 return out;
55275533 }
55285534