Skip to content

Commit

Permalink
netCDF multidim: fix use-after-free on string variables in ReadOneEle…
Browse files Browse the repository at this point in the history
…ment()
  • Loading branch information
rouault authored and github-actions[bot] committed Aug 13, 2024
1 parent b15aca7 commit 817153c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions autotest/gdrivers/netcdf_multidim.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,15 @@ def dims_from_non_netcdf(rg):
assert var
assert var.Read() == ["", "0123456789"]

var = rg.CreateMDArray(
"my_var_string_array_zero_dim", [], gdal.ExtendedDataType.CreateString()
)
assert var
assert var.Write(["foo"]) == gdal.CE_None
var = rg.OpenMDArray("my_var_string_array_zero_dim")
assert var
assert var.Read() == ["foo"]

f()

def f2():
Expand Down
2 changes: 1 addition & 1 deletion frmts/netcdf/netcdfmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3403,9 +3403,9 @@ bool netCDFVariable::ReadOneElement(const GDALExtendedDataType &src_datatype,
NCDF_ERR(ret);
if (ret != NC_NOERR)
return false;
nc_free_string(1, &pszStr);
GDALExtendedDataType::CopyValue(&pszStr, src_datatype, pDstBuffer,
bufferDataType);
nc_free_string(1, &pszStr);
return true;
}

Expand Down

0 comments on commit 817153c

Please sign in to comment.