From 935a55d69119650fde007caa494ee2a1c534fc52 Mon Sep 17 00:00:00 2001 From: Avi Date: Sat, 12 Nov 2022 11:57:49 +1000 Subject: [PATCH] Fix #86, Check return from chmod --- elf2cfetbl.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/elf2cfetbl.c b/elf2cfetbl.c index 5e8d813..ce3a81c 100644 --- a/elf2cfetbl.c +++ b/elf2cfetbl.c @@ -1436,6 +1436,7 @@ int32 OpenSrcFile(void) int32 OpenDstFile(void) { struct stat dststat; + int32 Status = SUCCESS; /* Check to see if output file can be opened and written */ DstFileDesc = fopen(DstFilename, "w"); @@ -1451,7 +1452,15 @@ int32 OpenDstFile(void) { if (Verbose) printf("%s: Destination file permissions after open = 0x%X\n", DstFilename, dststat.st_mode); - chmod(DstFilename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)); + + Status = chmod(DstFilename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)); + + if (Status != 0) + { + printf("%s: Error while attempting to modify file permissions\n", DstFilename); + return FAILED; + } + stat(DstFilename, &dststat); if (Verbose) printf("%s: Destination file permissions after chmod = 0x%X\n", DstFilename, dststat.st_mode);