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

Security threat in LogFile #42

@usmaanirfan

Description

@usmaanirfan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions