-
Notifications
You must be signed in to change notification settings - Fork 134
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
fix romimg bundled on docker containers #673
Conversation
tools/romimg/src/romimg.c
Outdated
#else | ||
char* UserName; | ||
#endif | ||
char LocalhostName[32] = "\0", cwd[128] = "\0", UserName[32] = "\0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that 128 is too short for computer usage. You should use MAX_PATH
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there is no cross platform definition of MAX_PATH. linux seems to use PATH_MAX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sorry PATH_MAX or whatever is called, I don't remember right now the POSIX solution for that hehe
5029ea8
to
699e6f2
Compare
instead of relying on strlen, go straight away with max bufsize
7c8a04d
to
2edbeef
Compare
@fjtrujy any idea with this compiler warning? not sure what to do to get rid of it. My local build (WSL) does not complain of this |
Add or remove one from either buffer or length |
will take a look. buffer is 11 and i'm reading 10 already |
29f4ef8
to
ce264c6
Compare
The buffer is being truncated. That is, the destination buffer is smaller than the source buffer. So increase the destination buffer size or decrease the source buffer size |
im kinda lost now
|
The error is quite easy, you do something like: strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name) - 1); This strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name)); And you also have it in other places as: strncpy(tbuf, fname, sizeof(tbuf) - 1); I think that in general the way of using strncpy(a, b, sizeof(a)); |
tools/romimg/src/romimg.c
Outdated
|
||
#include "platform.h" | ||
#include "romimg.h" | ||
#include "SonyRX.h" | ||
|
||
#define BUFCHK(X) (X[0] == '\0') ? "" : X |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this is really needed?
I think it makes no sense at all, the behavior should be the same, no matter if the first character is \0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it remained from older approach. will deal with it now
I realised I placed this recipe into the C makefile, leaving C++ and IOP C without this recipe
d8ce025
to
b575b96
Compare
fixed. seems to work as expected! |
Finally 😄 |
tools/romimg/src/romimg.c
Outdated
CommentLength = 31 + strlen(filename) + strlen(UserName) + strlen(LocalhostName) + strlen(cwd); | ||
ROMImg->comment = (char *)malloc(CommentLength); | ||
sprintf(ROMImg->comment, "%08x,conffile,%s,%s@%s/%s", ROMImg->date, filename, (UserName[0] =='\0')?"":UserName, LocalhostName, cwd); | ||
CommentLength = IMAGE_COMMENT_BASESIZE + strlen(filename) + sizeof(LocalhostName) + sizeof(UserName) + MAX_PATH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use sizeof
at the end
tools/romimg/src/platform.h
Outdated
|
||
#if defined(_WIN32) || defined(WIN32) | ||
#define PATHSEP '\\' | ||
#else | ||
#define PATHSEP '/' | ||
#endif | ||
#ifndef MAX_PATH | ||
#define MAX_PATH 4096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PATH_MAX
is available in all the OS, so use it instead and remove this from here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
windows has the name flipped MAX_PATH
instead of PATH_MAX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using MAX_PATH
in my fork and all the CI/CD was passing.
You are probably speaking about compiling natively, not through MinGW, in theory, we shouldn't care about these platforms...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure where it is defined then... everything in google says on limits.h but it's not the case
tools/romimg/src/romimg.c
Outdated
#else | ||
char* UserName; | ||
#endif | ||
char LocalhostName[32] = "\0", cwd[MAX_PATH] = "\0", UserName[32] = "\0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend to initializate them with = {0}
instead, it is equivalent to put all the fields with \0
directly
FILE *InputFile; | ||
int result; | ||
unsigned int FileDateStamp; | ||
unsigned short FileVersion; | ||
if ((InputFile = fopen(path, "rb")) != NULL) { | ||
const char* fname = strrchr(path, PATHSEP); | ||
if (fname == NULL) fname = path; else fname++; | ||
if (upperconv) { | ||
strncpy(tbuf, fname, sizeof(tbuf)); | ||
tbuf[sizeof(tbuf) - 1] = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you initialize with = {0}
then this line shouldn't be required either
1b630de
to
8dbb79a
Compare
instead of relying on strlen, go straight away with max bufsize. before this change the romimg from docker would segfault while local build works like a charm
New feature,
-c
and-a
commands will have new variants,-C
and-A
, these will manipulate the filename written to ROMFS removing extension and converting to uppercaseSo for example
romimg -C IOPRP.IMG $PS2SDK/iop/irx/secrman.irx
Will register secrman.irx as
SECRMAN
on the image, this seems to be needed when the IOPRP is replacing startup IOP modules