fixes AddressSanitizer: global-buffer-overflow in getAppFilename on windows 10 (#22380)

fixes AddressSanitizer: global-buffer-overflow
This commit is contained in:
norrath-hero-cn
2023-08-05 01:59:05 +08:00
committed by GitHub
parent 26f183043f
commit 73a29d72e3

View File

@@ -638,14 +638,14 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noW
# /proc/<pid>/path/a.out (complete pathname)
when defined(windows):
var bufsize = int32(MAX_PATH)
var buf = newWideCString("", bufsize)
var buf = newWideCString(bufsize)
while true:
var L = getModuleFileNameW(0, buf, bufsize)
if L == 0'i32:
result = "" # error!
break
elif L > bufsize:
buf = newWideCString("", L)
buf = newWideCString(L)
bufsize = L
else:
result = buf$L