Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Security threat in LogFile #42

Open
usmaanirfan opened this issue Feb 13, 2020 · 0 comments
Open

Security threat in LogFile #42

usmaanirfan opened this issue Feb 13, 2020 · 0 comments

Comments

@usmaanirfan
Copy link

Hi,

I am getting security threat in below code for LogFile.m class

  • (void)markPosition:(NSInteger)position
    {
    NSString* markString = [NSString stringWithFormat:@"%ld", (long)position];
    NSString* markPath = [self markPath];
    NSError* error = nil;
    BOOL r = [markString writeToFile:markPath atomically:YES encoding:NSASCIIStringEncoding error:&error];
    if (!r) {
    LE_DEBUG(@"Error marking read position to file '%@'", error);
    }
    self.bytesProcessed = position;
    }

Below is the issue description and some suggestions from security tool.

Issue : The call to writeToFile:atomically:encoding:error:() at LogFile.m line 229 uses methods which write to temporary files before writing to the targeted file.

Recommendations- To avoid this problem, work with file descriptors instead of file paths. Initialize an NSFileHandle object with the file descriptor and use NSFileHandle methods to write to the file.

Thanks and Regards,
Usman Ansari

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant