[2.0.x] Buffer overflow fixes and UTF8 cleanup#10844
[2.0.x] Buffer overflow fixes and UTF8 cleanup#10844thinkyhead merged 8 commits intoMarlinFirmware:bugfix-2.0.xfrom ejtagle:bugfix-2.0.x
Conversation
…cation of UTF8 chars and possible buffer overflow
|
Overall, looks good. I can't tell if the message string is still being padded out with spaces. That's important to make sure a previous longer message is erased by a new shorter message. I don't have my character display on hand at the moment, but I can test that tomorrow. Under the current policy, once you make an equivalent PR for |
|
@MagoKimbra says this broke things on his display. Are there any other people having problems with their LCD Panel (because of this commit) ? |
|
@Roxy-3D : I did test 2.0.x with a graphical display. I have no way to test 1.1.x. If @MagoKimbra is kind enough to describe the problem (some pictures would be nice) i think it can be fixed (but, again, logically i see no problems) |
|
I understand. Nobody else is saying anything, so let's just sit tight and wait for more information from MagoKimbra. |
|
Wow! That does look interesting! |
|
I download firmware 2.0 default parameters change only G3D display... Arduino IDE 1.8.5 and i have all library. With the last commit it's all ok... |
|
@MagoKimbra : Could you comment out the "lcd_scroll" function ? ... (i mean, just |
|
Yes i try!!! on moment! |
|
No the problem is same. |
|
@MagoKimbra : If you look at ultralcd_impl_HD44780.h, there is a You can also try either disabling the STATUS_MESSAGE_SCROLLING configuration, or commenting out that piece of code. The idea is to isolate the change that is causing the problem |
|
(the main problem is that i don´t have a HD44780 lcd attached to the printer... ;( ) -- Right now i am seriously considering in writing an emulator based on avrsim, so all those kinds of tests can be done by everybody without needing hardware |
|
I'm slowly modifying the code by going back to the hd44780 files ... |
|
@MagoKimbra : I think i found the problem!! ... Please, in file lcdprint_hd44780.cpp, look for the function lcd_put_u8str_max_cb. There it is a line that says: |
|
I am not sure how that change slipped. I modified that function, in both the graphics display version and the text display version. But somehow i forgot to do that important change to the text version. Without it, the function is unable to detect the end of the string... :( |
|
Ok i found the problem... In lcdprint_hd44780.cpp the routine lcd_put_u8str_max and lcd_put_u8str_max_P |
|
@MagoKimbra : I posted the possible fix ...
|
|
Ok now function... in |
|
Ops... you had the solution... Ok it's ok now... |

As said, G26 command processing had a buffer overflow.
Also removed some unneeded hacks
Clean up of UTF8 handling and possible buffer overflows: It must be clear that the UTF8 representation of characters can use more than 1 byte per character. So, for example, strlen(buffer) will always return the count of BYTES (not characters) required to store an UTF8 string. strcpy and strcat works.
But, strncpy() has a problem, as the count passed to that function is in bytes, not in characters. That could lead to truncation in the middle of a multibyte UTF8 character, and then and invalid UTF8 character is stored.
The routines used (get_utf8_value_cb) to fetch UTF8 chars do not validate that, thus, the end of the UTF8 string will not be detected.
So, it is of paramount importance to handle truncation in a proper way. This PR addresses that.
Also, removed unnecesary functions and simplified the UTF8 handling a bit.
Finally, the bug that was present when STATUS_MESSAGE_SCROLLING was defined (not proper estimation of scroll positions (UTF8 is multibyte) and the text was larger than the screen, was also fixed
I tried it on a Graphical display and it works. It would be nice if someone tries it in a text display 👍