diff --git a/tools/romimg/src/main.c b/tools/romimg/src/main.c index d60e6086178c..9a706ee3a3be 100644 --- a/tools/romimg/src/main.c +++ b/tools/romimg/src/main.c @@ -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++) { diff --git a/tools/romimg/src/romimg.c b/tools/romimg/src/romimg.c index 1bed3a35be1c..f917e659ef4c 100644 --- a/tools/romimg/src/romimg.c +++ b/tools/romimg/src/romimg.c @@ -6,11 +6,16 @@ #include #include #include +#include +#include #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; @@ -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; @@ -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,,@/ */ - 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;