Skip to content

Commit

Permalink
Check for NULL APIs returned by sai_api_query() before calling. (open…
Browse files Browse the repository at this point in the history
…computeproject#1558)

Signed-off-by: Chris Sommers <chrispsommers@gmail.com>

Co-authored-by: Chris Sommers <chrispsommers@gmail.com>
  • Loading branch information
chrispsommers and chrispsommers authored Aug 7, 2022
1 parent 8a66369 commit 47a9876
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 47a9876

Please sign in to comment.