Skip to content

Commit 7650d83

Browse files
authored
[UR] Check null pointer before handle in validation layer (#17474)
- Adjust mako template for ur_valddi.cpp so that pointers are null-checked before handles - Fixes issue with handles inside a pointer to a struct where the pointer would be dereferenced to check for a null handle before the pointer itself was null checked. - Updates some tests which passed additional null pointer args when checking for null handle errors, which would fail since the null pointer errors take priority now. Issue was found during coverity scan.
1 parent a111e4b commit 7650d83

File tree

5 files changed

+488
-483
lines changed

5 files changed

+488
-483
lines changed

unified-runtime/scripts/templates/valddi.cpp.mako

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ namespace ur_validation_layer
3333
3434
param_checks=th.make_param_checks(n, tags, obj, meta=meta).items()
3535
first_errors = [X + "_RESULT_ERROR_INVALID_NULL_POINTER", X + "_RESULT_ERROR_INVALID_NULL_HANDLE"]
36-
sorted_param_checks = sorted(param_checks, key=lambda pair: False if pair[0] in first_errors else True)
36+
# Sort param_checks such that anything in first_errors comes first while respecting the order of values in first_errors.
37+
# It is possible to have a pointer to a struct with a handle member, so pointers should be checked first.
38+
sorted_param_checks = sorted(param_checks, key=lambda pair: (0, first_errors.index(pair[0])) if pair[0] in first_errors else (1, 0))
3739
3840
tracked_params = list(filter(lambda p: any(th.subt(n, tags, p['type']) in [hf['handle'], hf['handle'] + "*"] for hf in handle_create_get_retain_release_funcs), obj['params']))
3941
%>

0 commit comments

Comments
 (0)