Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for NULL APIs returned by sai_api_query() and handle gracefully instead of crashing. #1558

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions meta/templates/sai_rpc_server_functions.tt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
[% END -%]
[%- END -%]

[%- BLOCK check_sai_function -%]
[% name = function.name; UNLESS methods.$name %]
[% END -%]
if ([% api %]_api->[% name = function.name; GET methods.$name %] == (void *)0) {
std::cerr << "NULL ptr: [% api %]_api->[% name = function.name; GET methods.$name %]" << std::endl;
[%- PROCESS throw_null_api_exception %]
}

[%- END -%]

[%- ######################################################################## -%]

[%- ######################################################################## -%]
Expand Down Expand Up @@ -133,6 +143,14 @@
[% indent %]throw e;
[%- END -%]

[%- BLOCK throw_null_api_exception -%]
[%- indentation = indentation || 2; tab = 2; indent = ' '; indent = indent.repeat(tab*indentation) %]

[% indent %]sai_thrift_exception e;
[% indent %]e.status = SAI_STATUS_NOT_IMPLEMENTED;
[% indent %]throw e;
[%- END -%]

[%- ######################################################################## -%]

[%- ######################################################################## -%]
Expand Down Expand Up @@ -351,6 +369,9 @@

[%- PROCESS preprocess_arguments %]

[%- # Ensure function ptr not NULL -%]
[% name = function.name; UNLESS methods.$name %]//[% END %][% PROCESS check_sai_function -%]

[%- # Now just call the function -%]
[% name = function.name; UNLESS methods.$name %]//[% END %]status = [% PROCESS call_sai_function -%]

Expand Down