Skip to content
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 #780, restrict permissions on file create #827

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 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 @@ -55,10 +56,17 @@ typedef struct

bool UtMem2BinFile(const void *Memory, const char *Filename, uint32 Length)
{
FILE *fp;
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 @@ -95,12 +103,18 @@ bool UtBinFile2Mem(void *Memory, const char *Filename, uint32 Length)

bool UtMem2HexFile(const void *Memory, const char *Filename, uint32 Length)
{
FILE * fp;
uint32 i;
uint32 j;
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)
{
Expand Down