Skip to content
Permalink
Browse files Browse the repository at this point in the history
netCDF: avoid buffer overflow. master only. Fixes https://bugs.chromi…
  • Loading branch information
rouault committed Jun 6, 2019
1 parent 311baa2 commit 767e3a5
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions gdal/frmts/netcdf/netcdfsg.cpp
Expand Up @@ -54,26 +54,21 @@ namespace nccfdriver
*/
std::string& attrf(int ncid, int varId, const char * attrName, std::string& alloc)
{
alloc = "";

size_t len = 0;
nc_inq_attlen(ncid, varId, attrName, &len);

if(len < 1)
{
alloc.clear();
return alloc;
}

char attr_vals[NC_MAX_NAME + 1];
memset(attr_vals, 0, NC_MAX_NAME + 1);
alloc.resize(len);
memset(&alloc[0], 0, len);

// Now look through this variable for the attribute
if(nc_get_att_text(ncid, varId, attrName, attr_vals) != NC_NOERR)
{
return alloc;
}
nc_get_att_text(ncid, varId, attrName, &alloc[0]);

alloc = std::string(attr_vals);
return alloc;
}

Expand Down

0 comments on commit 767e3a5

Please sign in to comment.