Fix using macro with regex in path parameter in fbtrace.conf#8238
Conversation
| if (flags & FORCE_SLASHES_INSTEAD_OF_BACKSLASHES) | ||
| { | ||
| size_t pos = 0; | ||
| while ((pos = macro.find('\\', pos)) != String::npos) | ||
| macro[pos] = '/'; | ||
| } | ||
| else | ||
| { | ||
| // Avoid incorrect slashes in pathnames | ||
| PathUtils::fixupSeparators(value.begin()); | ||
| PathUtils::fixupSeparators(macro.begin()); | ||
| } |
There was a problem hiding this comment.
I'm trying to keep the old implementation, so I added FORCE_SLASHES_INSTEAD_OF_BACKSLASHES flag, but maybe we can just remove these PathUtils::fixupSeparators() because it will happen in PATH_PARAMETER after all parsing steps anyway?
There was a problem hiding this comment.
Please provide a sample of causing problems trace configuration
There was a problem hiding this comment.
database = %[\\/](employee).fdb
{
enabled = true
log_filename = $(root)\1.log
log_connections = true
time_threshold = 0
}
Log filename should be fb_root_path/employee.log, but we get fb_root_path/1.log.
There was a problem hiding this comment.
On Windows it doesn't even get created because it's trying to parse backslashes as part of regex pattern (\1, \2, etc) but encounters \d[ev] in the file path and throws an error:
DESKTOP-86JTPHF Tue Sep 3 10:37:29 2024
Trace plugin fbtrace returned error on call trace_create.
error while parsing trace configuration
line 195, element "log_filename": pattern is invalid
E:\dev\MyFirebird\firebird\output_x64_debug\1.log
AlexPeshkoff
left a comment
There was a problem hiding this comment.
I'm afraid suggested solution is not complete. Imagine someone types (in windows):
log_filename = $(root)\audit-logs\1.log
Some problems are hardly avoidable when same char is used for 2 different purposes, but lets try to minimize them.
I suggest to use something like REGEXP_SUPPORT instead FORCE_SLASHES_INSTEAD_OF_BACKSLASHES and carefully parse both value and macro (moreover, value should be parsed when flag is set even when no macro-subst is done) in order to replace backslash with slash when next char is not a digit. At the first glance it appears more generic. Certainly if someone called directory '1' and tries to use it for logs I do not know how to guess what to do with that.
If you are ready to review the initial design, I would suggest to use |
|
On 9/5/24 17:52, Dimitry Sibiryakov wrote:
Some problems are hardly avoidable when same char is used for 2
different purposes, but lets try to minimize them.
If you are ready to review the initial design, I would suggest to use
|$(1)| for subpattern substitutions.
Looks as a minimum interesting - but discussion is devel is needed for
such change.
|
Oh, for some reason I thought only firebird/src/utilities/ntrace/TraceConfiguration.cpp Lines 291 to 297 in 72cc088 So I guess the problem only remains on Linux because of PathUtils::fixupSeparators(value.begin()); will fixup \1 regex pattern.I will do another test tomorrow. |
We should write path like this: |
|
Macro in config design supposed to provide smart behavior when merging paths, i.e. one need not know that $(root) already has \ at the end. In linux having double dir separators one after another (something like /usr//bin instead /usr/bin) is not dangerous but I'm not sure for other OS-es. Anyway, resulting file name may get visible to user somewhere else, i.e. I prefer to have correctly merged paths, not relying on presence of // at the end. Also we always tried to have config format as OS independent as possible, i.e. one should be able to have |
|
Tested on these file paths: |
|
I suggest you backport changes to previous versions |
|
I will backport it. |
Currently we cannot use macro with regex in path parameter because
PathUtils::fixupSeparators(value.begin());happens too early, and it will fix\1to/1before we replace it with regex group, so we get unexpected path.On Windows, we just get an error, because
PathUtils::fixupSeparators(value.begin());will change all/to\, and it will causeexpandPattern()to throw an exception.