Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
Updates os400qc3 key loading to open PEM/key files in binary mode and simplifies the fopen mode handling.
Changes:
- Remove
static constfopen mode strings ("r","rb") used for file opens. - Open RSA private key files using
"rb"for both PEM parsing and DER fallback attempts.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/os400qc3.c:2145
- In the DER fallback,
filesizeis taken directly fromftell(fp)without checking for errors.ftell()can return-1L; in that casefilesize <= 32768will be true anddatalenbecomes a hugesize_t, leading to an unboundedalloca()and potential crash. Check the return values offseek/ftell, requirefilesize >= 0, and only proceed when the size is valid.
fseek(fp, 0L, SEEK_END);
filesize = ftell(fp);
if(filesize <= 32768) { /* Limit to a reasonable size. */
datalen = filesize;
data = (unsigned char *) alloca(datalen);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ecedc46 to
08152b4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fseek(fp, 0L, SEEK_END); | ||
| filesize = ftell(fp); | ||
|
|
||
| if(filesize <= 32768) { /* Limit to a reasonable size. */ | ||
| if(filesize > 0 && | ||
| filesize <= 32768) { /* Limit to a reasonable size. */ |
There was a problem hiding this comment.
In the DER fallback, fseek(fp, 0L, SEEK_END) and ftell(fp) return values aren’t checked. If fseek() fails, the file position becomes unspecified and ftell() can yield a misleading non-negative value, causing an incorrect filesize to be used. Consider handling errors explicitly (check fseek(...) == 0 and filesize >= 0) similar to _libssh2_pem_parse() in src/pem.c:121-146.
There was a problem hiding this comment.
sure, but not walking into this rabbit hole at this time. Also: pre-existing issue.
|
@monnerat Your thoughts on this PR? |
To make
ftell()return a byte offset.Also:
ftell()returning -1 when loading DER format.Follow-up to 0ca33b6 #1883