Conversation
There was a problem hiding this comment.
Code Review
This pull request updates pointer arithmetic in stdlib/mktemp.c by adding a cast to the buffer argument in a read call. Feedback suggests using char * instead of void * to ensure standard C compliance and improve portability, as arithmetic on void * is a non-standard GCC extension.
cc2558f to
f9ce062
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request modifies stdlib/mktemp.c to cast the rand buffer to unsigned char * during a read system call. A review comment identifies a critical issue where the signedness of the rand array could lead to out-of-bounds access during subsequent modulo operations, suggesting that the array itself should be declared as unsigned.
| ssize_t err; | ||
| do { | ||
| err = read(fd, rand + sizeof(rand) - left, left); | ||
| err = read(fd, (unsigned char *)rand + sizeof(rand) - left, left); |
There was a problem hiding this comment.
The use of a signed int array for rand (line 50) causes a bug on line 68. When rand[i] is negative, the modulo operation rand[i] % (sizeof(pfcs) - 1) results in a negative value, leading to an out-of-bounds access into pfcs. It is recommended to change the declaration of rand to unsigned char rand[6] (and update the read size) or unsigned int rand[6]. This would resolve the signedness issue and simplify the pointer arithmetic in this read call.
TASK: RTOS-1275
f9ce062 to
69e3cc3
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates stdlib/mktemp.c to use an unsigned int array for random data and adds an explicit cast to unsigned char * when calling the read function. These changes improve type safety and ensure correct byte-level pointer arithmetic when populating the buffer. I have no feedback to provide as there were no review comments to evaluate.
Unit Test Results9 553 tests +29 8 961 ✅ +26 52m 12s ⏱️ - 1m 38s Results for commit 69e3cc3. ± Comparison against base commit 321f292. This pull request removes 1 and adds 30 tests. Note that renamed tests count towards both. |
TASK: RTOS-1275
Description
In the modified line of code the variable
randis of typeint[6]which decays intoint*and the+operator onint*will increment in multiples ofsizeof(int), thereforerand + sizeof(rand)was not the same as&rand[6], it was actually&rand[24]. The only reason it ever worked is that pretty much always thereadfrom/dev/urandomwould read in one go and on the first callsizeof(rand)andleftcancel out.Motivation and Context
Just noticed it while reading the code and decided to fix it.
Types of changes
How Has This Been Tested?
armv8m-stm32n6.Checklist:
Special treatment