-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory issues caused by erroneous sizeof
usage and others
#125
Labels
Comments
ericonr
added a commit
that referenced
this issue
Apr 8, 2022
This flag, since it removes builtin function usage entirely, can remove opportunity for potential compiler optimizations to be applied in some places, and, more importantly, some extra diagnostic warnings that can appear when the compiler uses the builtin versions of functions (which is what happened to point out the issues in [1]). Unfortunately, removing the flag breaks our build. Using -fno-builtin-printf is enough to fix it, so a safe assumption is that when using builtin printf(), the compiler can switch it for different functions (say, puts()), which we don't have our own implementation for, meaning the libc version is used and that one requires some extra functions for the underlying stdio implementation to work. [1] #125
augustofg
pushed a commit
that referenced
this issue
Jun 9, 2022
This flag, since it removes builtin function usage entirely, can remove opportunity for potential compiler optimizations to be applied in some places, and, more importantly, some extra diagnostic warnings that can appear when the compiler uses the builtin versions of functions (which is what happened to point out the issues in [1]). Unfortunately, removing the flag breaks our build. Using -fno-builtin-printf is enough to fix it, so a safe assumption is that when using builtin printf(), the compiler can switch it for different functions (say, puts()), which we don't have our own implementation for, meaning the libc version is used and that one requires some extra functions for the underlying stdio implementation to work. [1] #125
This was referenced May 16, 2023
Closed
This was introduced by c692454, it worked before because |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thankfully, it seems most of these code paths aren't in use at the moment.
Loops through struct with an
uint32_t
pointer but usingsizeof(board_diagnostic_t)
directly (without dividing by 4), as if it were anunsigned char
pointer (causes a buffer overflow). I think this is wrong in general with aliasing restrictions (a memcpy'd buffer would be more correct), but we do pass-fno-strict-aliasing
to the compiler, so that part shouldn't be a concern.openMMC/modules/fpga_spi.c
Lines 54 to 60 in a631724
Does
memset(buffer, size, value)
instead ofmemset(buffer, value, size)
. I'm not sure thismemset
needs to be here at all, since it immediately reads the I2C information into the buffer, therefore initializing it (unless the expectation after the I2C read is the presence of a null byte in the buffer). Should probably be replaced by a stack array, by setting a maximum size for the buffer.openMMC/port/board/afc-bpm/v3_1/ipmi_oem.c
Line 83 in a631724
Uses
sizeof(hpm_page)
whenhpm_page
is a pointer, making most calculations based on it wrong; this is happening all across the file. At least for the firstmemset
call,sizeof(hpm_page)
should probably be replaced withPAYLOAD_HPM_PAGE_SIZE
, which is the size passed to the allocator.openMMC/port/board/afc-bpm/v3_1/payload.c
Lines 326 to 344 in a631724
The text was updated successfully, but these errors were encountered: