Project

General

Profile

Bug #2369 ยป test.rb

wanabe (_ wanabe), 11/15/2009 02:11 PM

 
1
require 'dl/import'
2
module Kernel32
3
  extend DL::Importer
4
  dlload "kernel32.dll"
5
  typealias('DWORD', 'unsigned long')
6
  typealias('LPCSTR', 'const unsigned char *')
7
  typealias('LPSTR', 'unsigned char *')
8
  extern 'DWORD GetEnvironmentVariableA(LPCSTR,LPSTR,DWORD)'
9
end
10

    
11
ENV["FOO"] = "x"  * 0x7ff8
12

    
13
### != 0x7ff8
14
p ENV["FOO"].length 
15

    
16
### == 0x7ff8
17
buf = "\0" * 0x8000
18
Kernel32.GetEnvironmentVariableA("FOO", buf, buf.size)
19
p buf.gsub("\0", "").length
20

    
21
1000.times do |i|
22
  ENV["FOO"] = "x"  * 0x8000
23
end
24

    
25
### not reached (SEGV)
26
puts "ok"