Replace csprintf() in windows version of nimGetProcAddr to pure nim's implementation, to avoid possible overflow.
This commit is contained in:
parent
3b732259c0
commit
40f4fe997f
1 changed files with 23 additions and 2 deletions
|
|
@ -109,9 +109,30 @@ elif defined(windows) or defined(dos):
|
|||
proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
|
||||
result = getProcAddress(cast[THINSTANCE](lib), name)
|
||||
if result != nil: return
|
||||
var decorated: array[250, char]
|
||||
const decorated_length = 250
|
||||
var decorated: array[decorated_length, char]
|
||||
decorated[0] = '_'
|
||||
var m = 1
|
||||
while m < (decorated_length - 5):
|
||||
if name[m - 1] == '\x00': break
|
||||
decorated[m] = name[m - 1]
|
||||
inc(m)
|
||||
decorated[m] = '@'
|
||||
for i in countup(0, 50):
|
||||
discard csprintf(decorated, "_%s@%ld", name, i*4)
|
||||
var k = i * 4
|
||||
if k div 100 == 0:
|
||||
if k div 10 == 0:
|
||||
m = m + 1
|
||||
else:
|
||||
m = m + 2
|
||||
else:
|
||||
m = m + 3
|
||||
decorated[m + 1] = '\x00'
|
||||
while true:
|
||||
decorated[m] = chr(ord('0') + (k %% 10))
|
||||
dec(m)
|
||||
k = k div 10
|
||||
if k == 0: break
|
||||
result = getProcAddress(cast[THINSTANCE](lib), decorated)
|
||||
if result != nil: return
|
||||
procAddrError(name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue