Opened 17 years ago

Closed 17 years ago

#1720 closed defect (fixed)

[PATCH] Fixes minor Valgrind warning in DTED driver

Reported by: Even Rouault Owned by: warmerdam
Priority: normal Milestone: 1.5.0
Component: GDAL_Raster Version: 1.4.2
Severity: normal Keywords: dted
Cc:

Description

Currently, the DTED driver in creation mode generates a lot of times the following error :

==25042== Invalid read of size 1
==25042==    at 0x4022493: strlen (mc_replace_strmem.c:246)
==25042==    by 0x414C5A1: DTEDSetMetadata (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x414FC2D: DTEDCreateCopy(char const*, GDALDataset*, int, char**, int (*)(double, char const*, void*), void*) (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x422EAC8: GDALDriver::CreateCopy(char const*, GDALDataset*, int, char**, int (*)(double, char const*, void*), void*) (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x422EBD6: GDALCreateCopy (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x804B784: ProxyMain(int, char**) (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/apps/.libs/gdal_translate)
==25042==    by 0x804B86A: main (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/apps/.libs/gdal_translate)
==25042==  Address 0x4BE9C10 is 0 bytes after a block of size 80 alloc'd
==25042==    at 0x4021620: malloc (vg_replace_malloc.c:149)
==25042==    by 0x424BBBC: VSIMalloc (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x424002E: CPLMalloc (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x414CCAC: DTEDOpen (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x414F98D: DTEDCreateCopy(char const*, GDALDataset*, int, char**, int (*)(double, char const*, void*), void*) (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x422EAC8: GDALDriver::CreateCopy(char const*, GDALDataset*, int, char**, int (*)(double, char const*, void*), void*) (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x422EBD6: GDALCreateCopy (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/.libs/libgdal.so.1.11.2)
==25042==    by 0x804B784: ProxyMain(int, char**) (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/apps/.libs/gdal_translate)
==25042==    by 0x804B86A: main (in /home/even/downloads/mapserver/gdal-1.4.2-dted-invalid-read/apps/.libs/gdal_translate)

The following patch fixes that easily (pszFieldSrc is not NULL terminated) :

--- gdal-1.4.2.ori/frmts/dted/dted_api.c        2007-07-28 13:59:18.000000000 +0200
+++ gdal-1.4.2-dted-invalid-read/frmts/dted/dted_api.c  2007-07-29 11:59:21.000000000 +0200
@@ -528,7 +528,7 @@
 /* -------------------------------------------------------------------- */
     memset( pszFieldSrc, ' ', nFieldLen );
     strncpy( pszFieldSrc, pszNewValue,
-             MIN(strlen(pszFieldSrc),strlen(pszNewValue)) );
+             MIN(nFieldLen,strlen(pszNewValue)) );

 /* -------------------------------------------------------------------- */
 /*      Write all headers back to disk.                                 */

Attachments (1)

gdal-1.4.2-dted-invalid-read.patch (714 bytes ) - added by Even Rouault 17 years ago.

Download all attachments as: .zip

Change History (2)

by Even Rouault, 17 years ago

comment:1 by warmerdam, 17 years ago

Component: defaultGDAL_Raster
Milestone: 1.5.0
Resolution: fixed
Status: newclosed

Patch applied in trunk.

Thanks

Note: See TracTickets for help on using tickets.