Repository navigation
Ensure that created log files' names start with the specified name - #6236
Merged
Merged
Conversation
Prior to this change, if suffixLogs (i.e. TR_EnablePIDExtension) was enabled (which by default it is), log files for compilation threads other than compilation thread 0 would be opened using a name consisting of only the extra suffix, e.g. ".193310.88163.20211109.150243.193310". The cause was as follows: 1. When openLogFile() got a valid idSuffix, it would concatenate _logFileName with it into a stack buffer (filename). 2. Then when suffixLogs was also enabled, it would use the same stack buffer (filename) as the destination for the concatenation of the name so far (e.g. foo.log.1) with the PID and time. This was a call to sprintf() in which the destination buffer was also passed as an argument corresponding to a %s format specifier. This could (depending on platform?) behave as though the string argument was just an empty string. Note that the compilation thread ID was also lost, so any threads other than compilation thread 0 could pass the same filename to trfopen() if they started to trace within the same second, resulting in too few log files created. Since trfopen() is implemented via fopen(), we can expect that such a log opened multiple times will be truncated on each open (after the first). This problem is fixed by replacing the single buffer (filename) on the stack with a pair of buffers (buf0, buf1). At any given time, one is considered the next destination (destBuf). After formatting into destBuf, the buffers are swapped to ensure that it is safe to format into destBuf again. With this pair of buffers in place, it is no longer necessary to declare another buffer (tmp) for getFormattedName().
sprintf() is unsafe and should not be used.
Contributor
Author
|
@dsouzai, could I get your review? |
dsouzai
approved these changes
Nov 10, 2021
Contributor
|
Jenkins build all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior to this change, if
suffixLogs(i.e.TR_EnablePIDExtension) was enabled (which by default it is), log files for compilation threads other than compilation thread 0 would be opened using a name consisting of only the extra suffix, e.g. ".193310.88163.20211109.150243.193310".The cause was as follows:
When
openLogFile()got a valididSuffix, it would concatenate_logFileNamewith it into a stack buffer (filename).Then when
suffixLogswas also enabled, it would use the same stack buffer (filename) as the destination for the concatenation of the name so far (e.g.foo.log.1) with the PID and time. This was a call tosprintf()in which the destination buffer was also passed as an argument corresponding to a%sformat specifier. This could (depending on platform?) behave as though the string argument was just an empty string.Note that the compilation thread ID was also lost, so any threads other than compilation thread 0 could pass the same filename to
trfopen()if they started to trace within the same second, resulting in too few log files created. Sincetrfopen()is implemented viafopen(), we can expect that such a log opened multiple times will be truncated on each open (after the first).This problem is fixed by replacing the single buffer (
filename) on the stack with a pair of buffers (buf0,buf1). At any given time, one is considered the next destination (destBuf). After formatting intodestBuf, the buffers are swapped to ensure that it is safe to format intodestBufagain. With this pair of buffers in place, it is no longer necessary to declare another buffer (tmp) forgetFormattedName().There is one additional commit to remove uses of
sprintf()in OMROptions.cpp