Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion dap/DapUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,22 @@
}
else {
// width_ll() returns the number of bytes needed to hold the data
uint64_t vsize = var->width_ll(true);
uint64_t vsize = 0;
// If the data type is string, in C++, sizeof(string) is always 24. So the total size for a string array is
// always 24 x number of elements of this array, which may cause false positive for the server to issue
// an error that the maximum response size is exceeded. To avoid this case, we choose to use the minimal possible string size
// for a C string 2: 1 character and 1 terminator. This is also the case for a real NASA file.
if (var->type()==dods_array_c && var->var()->type() == dods_str_c)
vsize = 2*var->length_ll();
else
vsize = var->width_ll(true);
response_size += vsize;

BESDEBUG(MODULE_VERBOSE, prolog << " " << get_dap_decl(var) << "(" << vsize << " bytes)" << endl);
if ( (max_var_size > 0) && (vsize > max_var_size) ) {
string entry = get_dap_decl(var) + " (" + to_string(vsize) + " bytes)";
too_big.emplace_back(entry);
BESDEBUG(MODULE,

Check warning on line 325 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_var_size' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEn&open=AZ8ZDVpnKzZHLt4jHoEn&pullRequest=1405
prolog << get_dap_decl(var) << "(" << vsize
<< " bytes) is bigger than the max_var_size of "
<< max_var_size << " bytes. too_big.size(): " << too_big.size() << endl);
Expand Down Expand Up @@ -451,7 +459,7 @@

// The BES configuration is help in TheBESKeys, so we read from there.
uint64_t config_max_resp_size = TheBESKeys::TheKeys()->read_uint64_key(BES_KEYS_MAX_RESPONSE_SIZE_KEY, 0);
BESDEBUG(MODULE, prolog << "config_max_resp_size: " << config_max_resp_size << "\n");

Check warning on line 462 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'config_max_resp_size' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEo&open=AZ8ZDVpnKzZHLt4jHoEo&pullRequest=1405
max_response_size_bytes = config_max_resp_size; // This is the default state, the command can only make it smaller

uint64_t cmd_context_max_resp_size;
Expand All @@ -473,11 +481,11 @@
max_response_size_bytes = cmd_context_max_resp_size;
}
}
BESDEBUG(MODULE, prolog << "max_response_size_bytes: " << max_response_size_bytes << "\n");

Check warning on line 484 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_response_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEp&open=AZ8ZDVpnKzZHLt4jHoEp&pullRequest=1405

// The BES configuration is help in TheBESKeys, so we read from there.
uint64_t config_max_var_size = TheBESKeys::TheKeys()->read_uint64_key(BES_KEYS_MAX_VAR_SIZE_KEY, 0);
BESDEBUG(MODULE, prolog << "config_max_var_size: " << config_max_var_size << "\n");

Check warning on line 488 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'config_max_var_size' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEq&open=AZ8ZDVpnKzZHLt4jHoEq&pullRequest=1405
max_var_size_bytes = config_max_var_size;

uint64_t cmd_context_max_var_size=0;
Expand All @@ -503,7 +511,7 @@
BESDEBUG(MODULE, prolog << "Adjusted max_response_size_bytes to DAP2 limit.\n");
}
}
BESDEBUG(MODULE, prolog << "max_var_size_bytes: " << max_var_size_bytes << "\n");

Check warning on line 514 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_var_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEr&open=AZ8ZDVpnKzZHLt4jHoEr&pullRequest=1405
}

/**
Expand All @@ -520,14 +528,14 @@
msg << "unlimited\n";
}
else {
msg << max_response_size_bytes << " bytes.\n";

Check warning on line 531 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_response_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEs&open=AZ8ZDVpnKzZHLt4jHoEs&pullRequest=1405
}
msg << " Maximum allowed variable size: ";
if(max_var_size_bytes == 0){
msg << "unlimited\n";
}
else {
msg << max_var_size_bytes << " bytes.\n";

Check warning on line 538 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_var_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEt&open=AZ8ZDVpnKzZHLt4jHoEt&pullRequest=1405
}
return msg.str();
}
Expand All @@ -554,8 +562,8 @@
bool is_dap2=false
){

BESDEBUG(MODULE, prolog << "max_response_size_bytes: " << max_response_size_bytes << "\n");

Check warning on line 565 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_response_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEu&open=AZ8ZDVpnKzZHLt4jHoEu&pullRequest=1405
BESDEBUG(MODULE, prolog << "max_var_size_bytes: " << max_var_size_bytes << "\n");

Check warning on line 566 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_var_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEv&open=AZ8ZDVpnKzZHLt4jHoEv&pullRequest=1405
BESDEBUG(MODULE, prolog << "response_size_bytes: " << response_size_bytes << "\n");
BESDEBUG(MODULE, prolog << "too_big_vars.size(): " << too_big_vars.size() << "\n");

Expand Down Expand Up @@ -633,8 +641,8 @@
std::vector<std::string> too_big_vars;

get_max_sizes_bytes(max_response_size_bytes, max_var_size_bytes);
BESDEBUG(MODULE, prolog << "max_var_size_bytes: " << max_var_size_bytes << "\n");

Check warning on line 644 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_var_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEw&open=AZ8ZDVpnKzZHLt4jHoEw&pullRequest=1405
BESDEBUG(MODULE, prolog << "max_response_size_bytes: " << max_response_size_bytes << "\n");

Check warning on line 645 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_response_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEx&open=AZ8ZDVpnKzZHLt4jHoEx&pullRequest=1405

auto response_size_bytes = compute_response_size_and_inv_big_vars(dmr, max_var_size_bytes, too_big_vars);
BESDEBUG(MODULE, prolog << "response_size_bytes: " << response_size_bytes << "\n");
Expand Down Expand Up @@ -669,8 +677,8 @@
std::vector<std::string> too_big_vars;

get_max_sizes_bytes(max_response_size_bytes, max_var_size_bytes, true);
BESDEBUG(MODULE, prolog << "max_var_size_bytes: " << max_var_size_bytes << "\n");

Check warning on line 680 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_var_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEy&open=AZ8ZDVpnKzZHLt4jHoEy&pullRequest=1405
BESDEBUG(MODULE, prolog << "max_response_size_bytes: " << max_response_size_bytes << "\n");

Check warning on line 681 in dap/DapUtils.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

tainted value 'max_response_size_bytes' is leaking

See more on https://sonarcloud.io/project/issues?id=opendap-bes&issues=AZ8ZDVpnKzZHLt4jHoEz&open=AZ8ZDVpnKzZHLt4jHoEz&pullRequest=1405

auto response_size_bytes = compute_response_size_and_inv_big_vars(dds, max_var_size_bytes, too_big_vars);
BESDEBUG(MODULE, prolog << "response_size_bytes: " << response_size_bytes << "\n");
Expand Down
4 changes: 2 additions & 2 deletions dap/unit-tests/DapUtilsTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class DapUtilsTest : public CppUnit::TestFixture {

stringstream msg;
uint64_t response_size = 0;
uint64_t expected_response_size = 1016;
uint64_t expected_response_size = 752;
uint64_t max_var_size = 200;
std::vector<std::string> too_big;

Expand All @@ -433,7 +433,7 @@ class DapUtilsTest : public CppUnit::TestFixture {
for(auto entry:too_big){
DBG(cerr << prolog << " " << entry << endl);
}
CPPUNIT_ASSERT( too_big.size() == 2 );
CPPUNIT_ASSERT( too_big.size() == 1 );
}
else {
CPPUNIT_FAIL("ERROR: No variables were deemed too big!");
Expand Down
Loading