use static initialization for output string in RenderCurrentFolder #473

Merged
stklcode merged 1 commits from fix/render-current-folder into master 2023-06-24 05:50:47 -05:00
stklcode commented 2023-06-24 05:31:16 -05:00 (Migrated from github.com)

Description

The dynamic sized variable outputString may not be properly initialized.

Second issue, we fill the line for directories beyond fileNameLength, so the initialization is not always sufficient.

00a74c15eb/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp (L912-L916)

In this case, fileNameWasCut == false, so fileNameLen < MAX_PRINTABLE_FILENAME_LEN and we declared outputString[fileNameLen].
So if fileNameLen > MAX_PRINTABLE_FILENAME_LEN - 7 we write beyond the array bounds.

Resolution

We now initialize outputString statically with the maximum printable size which should resolve both.

Also clean up some variable declarations.

Requirements

The described bug only affects targets with KNUTWURST_DGUS2_TFT.

The static initialization affects all targets.

Benefits

Resolves potential memory issues during file list rendering.

Configurations

none

none

### Description The dynamic sized variable `outputString` may not be properly initialized. Second issue, we fill the line for directories beyond `fileNameLength`, so the initialization is not always sufficient. https://github.com/knutwurst/Marlin-2-0-x-Anycubic-i3-MEGA-S/blob/00a74c15ebbb5f42076be3717b50162378733262/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp#L912-L916 In this case, `fileNameWasCut == false`, so `fileNameLen < MAX_PRINTABLE_FILENAME_LEN` and we declared `outputString[fileNameLen]`. So if `fileNameLen > MAX_PRINTABLE_FILENAME_LEN - 7` we write beyond the array bounds. **Resolution** We now initialize `outputString` statically with the maximum printable size which should resolve both. Also clean up some variable declarations. ### Requirements The described bug only affects targets with `KNUTWURST_DGUS2_TFT`. The static initialization affects all targets. ### Benefits Resolves potential memory issues during file list rendering. ### Configurations none ### Related Issues none
knutwurst commented 2023-06-24 05:50:41 -05:00 (Migrated from github.com)

Thanks!

Thanks!
Sign in to join this conversation.
No description provided.