This patch checks pointer after all calls to strchr just in case format of the location string is broken.
Patch by Andrey Churbanov
Differential D90962
[OpenMP] Fix possible NULL dereferences AndreyChurbanov on Nov 6 2020, 11:47 AM. Authored by
Details This patch checks pointer after all calls to strchr just in case format of the location string is broken. Patch by Andrey Churbanov
Diff Detail
Event TimelineComment Actions So, we had asserts, right? And this code is "copied" a few times all over. What I try to say is, I'm not sure this is a "fix" and it is sufficient. Comment Actions KMP_DEBUG_ASSERT is no-op in release build. Thus this patch adds missed checks in order to make static code analyzers happy. Comment Actions I don't think we should generally "make the static code analyzers happy" by swapping out reasonable asserts with some if-then-else logic for a case we don't expect to happen. Comment Actions I am still not sure I got your comment, let me clarify. What do you mean by "reasonable asserts"? As I pointed out the KMP_DEBUG_ASSERT is no-op in release build used by most people. Also what do you mean by "other copies of this code"? Comment Actions With your argumentation *every* assert should be replaced by an if (!expr) abort(0) regardless of NDEBUG. Assertions, by design, provide
I mean for example __kmp_str_loc_init, which does gracefully handle ill-formed input (as far as I can tell). Comment Actions
I'd vote for abandoning of this patch, rather than re-using __kmp_str_loc_init here. So I'd vote for faster execution here as opposed to elegant coding. Comment Actions Add function for reading numeric only values from location string. Use the function in metadata reporting for loop and single constructs. Usages of __kmp_str_loc_init() adjusted to remove unneeded initialization/finalization of fname field of kmp_str_loc_t structure. Comment Actions I like the approach. Minor nits and one question though: Why are we talking about two line numbers and not line + column? This confuses me.
Comment Actions This is historical discrepancy. The definition of the ident_t structure in kmp.h says: char const *psource; /**< String describing the source location. The string is composed of semi-colon separated fields which describe the source file, the function and a pair of line numbers that delimit the construct. */ So the two numbers initially supposed to indicate start and end of OpenMP construct. For standalone constructs they are coincide. Then in many places I see line/column naming of the two fields. I also was under the impression that these are line/column. Not sure what to do now with this discrepancy, the begin/end line of the code block looks preferable for tools those can consume this information.
Comment Actions LGTM, I left a nit inlined but feel free to ignore. Argh, ... OK, so the situation we are in is that the frontends are not in agreement. One thing we should avoid is to mix the comments in the runtime as well, will just cause more confusion. I'd argue we can let the frontends do what they think is right and in the runtime just say "this is a number that is either the line end or column". We always treat it the same, given that we don't interpret it anyway. Tools need to be aware of the frontend to avoid confusion. WDYT? (This would mean an action item to make sure all comments (maybe also variable names) reflect the duality.)
Comment Actions I've changed the type of init_fname parameter from int to bool; replaced names line_beg/line_end with line/col to be consistent with surrounding code; and changed parameter name LineEnd to LineEndOrCol, also adjusted comments on the definition of __kmp_str_loc_numbers to reflect the duality of the last field in location string. Feel free to comment post-commit if needed. |
Why do these inputs change?