Opened 8 years ago

Last modified 8 years ago

#6227 closed defect

Buffer overflow potential in netcdf driver — at Version 1

Reported by: Kurt Schwehr Owned by: warmerdam
Priority: normal Milestone: 1.11.4
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: netcdf
Cc:

Description (last modified by Kurt Schwehr)

https://www.unidata.ucar.edu/software/netcdf/docs/netcdf-c/nc_005finq_005fvar.html - note the "declare your array to be size NC_MAX_NAME+1" part

Usage

     int nc_inq_var      (int ncid, int varid, char *name, nc_type *xtypep,
                          int *ndimsp, int dimids[], int *nattsp);
     int nc_inq_varname  (int ncid, int varid, char *name);
     int nc_inq_vartype  (int ncid, int varid, nc_type *xtypep);
     int nc_inq_varndims (int ncid, int varid, int *ndimsp);
     int nc_inq_vardimid (int ncid, int varid, int dimids[]);
     int nc_inq_varnatts (int ncid, int varid, int *nattsp);

ncid NetCDF ID, from a previous call to nc_open or nc_create. 

varid Variable ID. 

name Returned variable name. The caller must allocate space for the 
  returned name. The maximum possible length, in characters, of a
  variable name is given by the predefined constant NC_MAX_NAME. 
  (This doesn't include the null terminator, so declare your array 
  to be size NC_MAX_NAME+1). The returned character array will be 
  null-terminated. 

e.g.

CPLErr netCDFRasterBand::CreateBandMetadata( int *paDimIds )

{
    netCDFDataset *poDS = reinterpret_cast<netCDFDataset *>( this->poDS );

/* -------------------------------------------------------------------- */
/*      Compute all dimensions from Band number and save in Metadata    */
/* -------------------------------------------------------------------- */
    char szVarName[NC_MAX_NAME];
    nc_inq_varname( cdfid, nZId, szVarName );

Change History (1)

comment:1 by Kurt Schwehr, 8 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.