Skip to content

Commit

Permalink
Fix #780, restrict permissions on file create
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Feb 22, 2021
1 parent ff4f523 commit 9e64376
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ut_assert/src/uttools.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>

#include "common_types.h"
#include "utassert.h"
Expand All @@ -56,9 +57,16 @@ typedef struct
bool UtMem2BinFile(const void *Memory, const char *Filename, uint32 Length)
{
FILE *fp;
struct stat dststat;

if ((fp = fopen(Filename, "w")))
{
{
if (stat(Filename, &dststat) == 0)
{
chmod(Filename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH));
stat(Filename, &dststat);
}

fwrite(Memory, Length, 1, fp);
fclose(fp);
return (true);
Expand Down Expand Up @@ -98,10 +106,16 @@ bool UtMem2HexFile(const void *Memory, const char *Filename, uint32 Length)
FILE * fp;
uint32 i;
uint32 j;
struct stat dststat;

if ((fp = fopen(Filename, "w")))
{

if (stat(Filename, &dststat) == 0)
{
chmod(Filename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH));
stat(Filename, &dststat);
}

for (i = 0; i < Length; i += 16)
{
fprintf(fp, " %06lX: ", (unsigned long)i);
Expand Down

0 comments on commit 9e64376

Please sign in to comment.