Ventoy/GRUB2/MOD_SRC/grub-2.04/grub-core
Celine Lee 9789069c0d
Modify casting in protection against underflow (#1514)
Dear Ventoy community –
 
Our team is working with your code and we noticed this if logical expression:
 
                if (len - 1 - (int)(long)(pos - pwdstr) != 32)
 
We studied the surrounding code. We believe we understand the intention of the type casts in the above if statement. It seems they were meant to ensure an underflow doesn’t occur by the subtraction between to char pointers, which is a great catch (!). However, we believe the way the type casts are structured, the code is not actually protecting against such underflow because pwdstr isn’t cast into a signed long until after the subtraction occurs. To properly protect this code against underflow, we believe it should be changed to something like the following:

if (len - 1 - ((long)pos – (long)pwdstr) != 32)

Or, to enhance readability for junior engineers who may not know that the “long” type cast is implicitly of a signed integer type, we could include the `signed` keyword for added verbosity:
 
if (len - 1 - ((signed long)pos – (signed long)pwdstr) != 32)
 
Thank you!
2022-03-26 10:29:18 +08:00
..
boot/i386/pc Code Optimize 2020-12-12 07:40:33 +08:00
commands Add .md5/.sha1/.sha256/.sha512 check file feature. 2021-10-24 18:52:09 +08:00
disk support custom arch iso (#1021) 2021-07-27 19:08:40 +08:00
font 1.0.53 release 2021-09-27 21:00:08 +08:00
fs 1.0.69 release 2022-02-15 22:04:50 +08:00
gfxmenu 1.0.53 release 2021-09-27 21:00:08 +08:00
kern 1.0.67 release 2022-02-14 23:31:54 +08:00
lib experimental support for loongson mips64el uefi 2021-03-05 23:03:34 +08:00
loader 1.0.51 release 2021-08-27 20:36:32 +08:00
normal Fixed to select the 1st menu item when switching between upper and lower sub-menus. 2022-02-14 14:29:50 +08:00
partmap experimental support for chromium os (fydeos/cloudready) 2021-08-26 14:17:44 +08:00
script Fix a bug when booting HDM17x64_17.20.0_ADV_Linux_Downloadly.ir.iso 2021-11-02 23:23:39 +08:00
term Add VTOY_DEFAULT_KBD_LAYOUT in global control plugin 2021-03-24 22:08:10 +08:00
ventoy Modify casting in protection against underflow (#1514) 2022-03-26 10:29:18 +08:00
Makefile.am experimental support for loongson mips64el uefi 2021-03-05 23:03:34 +08:00
Makefile.core.def 1.0.67 release 2022-02-14 23:31:54 +08:00