Compare commits

...
3 Commits
Author SHA1 Message Date
t3hn3rd 465107e904 fix: guard against uint32 underflow in memset/memcpy and strings unit
continuous-integration/drone/push Build is passing
When size=0 was passed to memset() or memcpy(), the loop bound
`0 to size-1` underflowed to $FFFFFFFF, iterating ~4 billion times
and causing an immediate page fault.

Added `if size = 0 then exit` guards to both memset() and memcpy()
in util.pas.

Also guarded all `for i:=0 to X-1` loops in strings.pas where X
could be 0 on empty string inputs:
- stringToUpper: wrap loop in `if stringSize > 0`
- stringToLower: wrap loop in `if stringSize > 0`
- stringEquals: early exit when both sizes are 0
- stringToInt: early exit when string is empty

Additionally fixed all previously identified bugs in strings.pas:
- hexStringToInt: guard against empty string underflow
- stringConcat: cache stringSize calls to avoid redundant O(n) scans
- stringTrim: clamp length to source string size
- stringSub: bounds check start/size against source length
- stringReplace: complete rewrite - was using stringEquals() for
  substring matching (only matched at string end), dropped prefix
  chars, had dangling assignment overwriting valid result with
  uninitialized pointer, and had unused variable
- stringIndexOf: rewritten to use new stringMatchAt() helper for
  correct substring matching
- stringContains: simplified to delegate to fixed stringIndexOf(),
  also fixing uint32 underflow when sub was empty
- stringToInt: removed always-true `v >= 0` check on uint32
- intToString: implemented (was a stub returning ' ')
- Added stringMatchAt() helper for prefix comparison
- Added comprehensive UnitTest procedure with 77 assertions
  including adversarial empty/nil/boundary inputs
2026-02-28 15:08:02 +00:00
t3hn3rd 3198d31027 Gitignore 2026-02-28 14:04:47 +00:00
admin 924305a1ab Merge pull request 'Migration from FPC 2.6.4 to FPC 3.2.2' (#9) from feature/fpc-3.2.2 into develop
continuous-integration/drone/push Build is passing
Reviewed-on: #9
2026-02-26 12:51:09 +00:00
4 changed files with 410 additions and 90 deletions

No files matched your search

+3
View File
@@ -11,3 +11,6 @@
/*.img /*.img
src/include/asuro.pas src/include/asuro.pas
localenv.json localenv.json
AGENTS.md
build.log
dockerout.txt
+403 -90
View File
File diff suppressed because it is too large. Load diff
+2
View File
@@ -428,6 +428,7 @@ var
begin begin
//push_trace('util.memset'); //push_trace('util.memset');
if size = 0 then exit;
for i:=0 to size-1 do begin for i:=0 to size-1 do begin
loc:= puint8(location + i); loc:= puint8(location + i);
loc^:= value; loc^:= value;
@@ -442,6 +443,7 @@ var
begin begin
//push_trace('util.memcpy'); //push_trace('util.memcpy');
if size = 0 then exit;
for i:=0 to size-1 do begin for i:=0 to size-1 do begin
src:= puint8(source + i); src:= puint8(source + i);
dst:= puint8(dest + i); dst:= puint8(dest + i);
+2
View File
@@ -262,6 +262,8 @@ begin
rand.srand((getDateTime.Seconds SHL 24) OR (getDateTime.Minutes SHL 16) OR (getDateTime.Hours SHL 8) OR (getDateTime.Day)); rand.srand((getDateTime.Seconds SHL 24) OR (getDateTime.Minutes SHL 16) OR (getDateTime.Hours SHL 8) OR (getDateTime.Day));
tracer.push_trace('kmain.TICK'); tracer.push_trace('kmain.TICK');
strings.UnitTest;
while true do begin while true do begin
tracer.push_trace('kmain.RedrawWindows'); tracer.push_trace('kmain.RedrawWindows');