Skip to content

Commit

Permalink
fix romimg bundled on docker containers
Browse files Browse the repository at this point in the history
instead of relying on strlen, go straight away with max bufsize
  • Loading branch information
israpps committed Nov 6, 2024
1 parent 67e800b commit 5029ea8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tools/romimg/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main(int argc, char **argv)
}
UnloadROMImg(&ROMImg);
} else
ERROR("(Internal fault) Can't create blank image file: %d. Please report.\n", result);
ERROR("(Internal fault) Can't create blank image file: %d (%s). Please report.\n", result, strerror(result));
} else if (argc >= 4 && strcmp(argv[1], "-a") == 0) {
if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) {
for (i = 0, FilesAffected = 0; i < argc - 3; i++) {
Expand Down
21 changes: 11 additions & 10 deletions tools/romimg/src/romimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>

#include "platform.h"
#include "romimg.h"
#include "SonyRX.h"

#define BUFCHK(X) (X[0] == '\0') ? "" : X
#define IMAGE_COMMENT_BASESIZE 31

struct ROMImgStat
{
void *image;
Expand Down Expand Up @@ -139,12 +144,7 @@ static int GetExtInfoStat(const struct ROMImgStat *ImageStat, struct RomDirFileF
int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
{
unsigned int CommentLength;
char LocalhostName[32], cwd[128];
#if defined(_WIN32) || defined(WIN32)
char UserName[32] = "";
#else
char* UserName;
#endif
char LocalhostName[32] = "\0", cwd[MAX_PATH] = "\0", UserName[32] = "\0";
struct FileEntry *ResetFile;
struct ExtInfoFieldEntry *ExtInfoEntry;

Expand All @@ -154,14 +154,15 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
#if defined(_WIN32) || defined(WIN32)
GetUsername(UserName, sizeof(UserName));
#else
UserName = getenv("USER");
getlogin_r(UserName, sizeof(UserName));
#endif
GetLocalhostName(LocalhostName, sizeof(LocalhostName));
GetCurrentWorkingDirectory(cwd, sizeof(cwd));
/* Comment format: YYYYMMDD-XXXYYY,conffile,<filename>,<user>@<localhost>/<image path> */
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;
ROMImg->comment = (char *)calloc(0, CommentLength+1);
if (!ROMImg->comment) return ENOMEM;
snprintf(ROMImg->comment, CommentLength, "%08x,conffile,%s,%s@%s/%s", ROMImg->date, filename, BUFCHK(UserName), BUFCHK(LocalhostName), cwd);

// Create a blank RESET file.
ROMImg->NumFiles = 1;
Expand Down

0 comments on commit 5029ea8

Please sign in to comment.