Actions
Bug #20096
closedRuby 3.2.2 win32/registry: Junk appended to Windows Registry String Value
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mswin64_140]
Description
Ruby Version:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mswin64_140]
Compiler: MSVC 2019 - Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30147 for x64.
Issue: win32/registry adds junk to Windows Registry String Value
Code:
require 'win32/registry'
win_oracle_key = "SOFTWARE\MicroSoft"
reg=Win32::Registry::HKEY_LOCAL_MACHINE.open(win_oracle_key, Win32::Registry::KEY_ALL_ACCESS)
inst_loc_key = "inst_loc"
inv_dir="C:\Program Files\Tester\ModuleInfo"
reg[inst_loc_key] = inv_dir
Result:
Registry contains:
C:\Program Files\Tester\ModuleInfo爀
Observation: Looks like memory overread
Expected Result - without the junk:
C:\Program Files\Tester\ModuleInfo
After changing the code in registry.rb:
From:
def write(name, type, data)
termsize = 0
case type
when REG_SZ, REG_EXPAND_SZ
data = data.encode(WCHAR)
termsize = WCHAR_SIZE
To:
def write(name, type, data)
termsize = 0
case type
when REG_SZ, REG_EXPAND_SZ
enc_data = data.encode(WCHAR)
# Add NULL WCHAR for string data and don't set the termsize because
# enc_data.bytesize will now include the size of the NULL character.
enc_data += WCHAR_NUL
# termsize = WCHAR_SIZE
...
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0