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
2 changes: 1 addition & 1 deletion include/xsf/amos/amos.h
Original file line number Diff line number Diff line change
Expand Up @@ -3752,7 +3752,7 @@ namespace amos {
nl = n - 1;
fnui = nl;
k = nl;
for (i = 0; i < (nl + 1); i++) {
for (i = 0; i < nl; i++) {
st = s2;
s2 = (fnu + fnui) * rz * s2 + s1;
s1 = st;
Expand Down
23 changes: 23 additions & 0 deletions tests/xsf_tests/test_amos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,26 @@ TEST_CASE("amos asyi buffer overflow gh-158", "[amos][xsf_tests]") {
CAPTURE(y[n]);
CHECK(y[n] == sentinel);
}

TEST_CASE("amos buni buffer overflow gh-93", "[amos][xsf_tests]") {
using std::complex;

// parameters for besh which trigger overflow in buni
const complex<double> z{90.0, -3.0};
const double fnu = 1.0;
const int m = 1;
const int n = 30;
const int kode = 1;

// allocate n+1 elements, initialize extra to sentinel to detect overflow
const complex<double> sentinel{12345.67, 98765.43};
std::vector<complex<double>> cy(n + 2, sentinel);

int ierr = 0;
int nz = xsf::amos::besh(z, fnu, kode, m, n, cy.data() + 1, &ierr);

// check if guards elements were touched
CAPTURE(cy[0], cy[n + 1]);
CHECK(cy[0] == sentinel);
CHECK(cy[n + 1] == sentinel);
}
Loading