[postgis-tickets] r15722 - #3847, coverity fixes around the loaders

Paul Ramsey pramsey at cleverelephant.ca
Thu Sep 14 06:52:26 PDT 2017


Author: pramsey
Date: 2017-09-14 06:52:25 -0700 (Thu, 14 Sep 2017)
New Revision: 15722

Modified:
   trunk/loader/dbfopen.c
   trunk/loader/pgsql2shp-core.c
   trunk/loader/shp2pgsql-core.c
   trunk/raster/loader/raster2pgsql.c
Log:
#3847, coverity fixes around the loaders


Modified: trunk/loader/dbfopen.c
===================================================================
--- trunk/loader/dbfopen.c	2017-09-13 21:51:22 UTC (rev 15721)
+++ trunk/loader/dbfopen.c	2017-09-14 13:52:25 UTC (rev 15722)
@@ -686,14 +686,22 @@
 /* -------------------------------------------------------------------- */
     fp = psHooks->FOpen( pszFullname, "wb" );
     if( fp == NULL )
+	{
+		free(pszBasename);
+		free(pszFullname);
         return( NULL );
+	}
 
     psHooks->FWrite( &chZero, 1, 1, fp );
     psHooks->FClose( fp );
 
     fp = psHooks->FOpen( pszFullname, "rb+" );
     if( fp == NULL )
+	{
+		free(pszBasename);
+		free(pszFullname);
         return( NULL );
+	}
 
 
     sprintf( pszFullname, "%s.cpg", pszBasename );

Modified: trunk/loader/pgsql2shp-core.c
===================================================================
--- trunk/loader/pgsql2shp-core.c	2017-09-13 21:51:22 UTC (rev 15721)
+++ trunk/loader/pgsql2shp-core.c	2017-09-14 13:52:25 UTC (rev 15722)
@@ -831,8 +831,11 @@
 				fp = fopen( pszFullname, "wb" );
 				if ( fp == NULL )
 				{
+					free(pszFullname);
+					free(query);
 					return 0;
 				}
+				else
 				{
 				    result = fputs (srtext,fp);
                     LWDEBUGF(3, "\n result %d proj SRText is %s .\n", result, srtext);
@@ -1738,7 +1741,10 @@
 			*/
 			dbffieldsize = getMaxFieldSize(state->conn, state->schema, state->table, pgfieldname);
 			if (dbffieldsize == -1)
+			{
+				free(dbffieldname);
 				return 0;
+			}
 
 			if (!dbffieldsize)
 				dbffieldsize = 32;
@@ -2087,6 +2093,7 @@
 			{
 				snprintf(state->message, SHPDUMPERMSGLEN, _("Error parsing HEXEWKB for record %d"), state->currow);
 				PQclear(state->fetchres);
+				free(hexewkb);
 				return SHPDUMPERERR;
 			}
 

Modified: trunk/loader/shp2pgsql-core.c
===================================================================
--- trunk/loader/shp2pgsql-core.c	2017-09-13 21:51:22 UTC (rev 15721)
+++ trunk/loader/shp2pgsql-core.c	2017-09-14 13:52:25 UTC (rev 15722)
@@ -703,6 +703,9 @@
 
 	if ( !mem )
 	{
+		/* Free the linked list of rings */
+		ReleasePolygons(Outer, polygon_total);
+
 		snprintf(state->message, SHPLOADERMSGLEN, "unable to write geometry");
 		return SHPLOADERERR;
 	}
@@ -784,7 +787,7 @@
 	state->precisions = NULL;
 	state->col_names = NULL;
 	state->field_names = NULL;
-	state->num_fields = NULL;
+	state->num_fields = 0;
 	state->pgfieldtypes = NULL;
 
 	state->from_srid = config->shp_sr_id;
@@ -1613,10 +1616,10 @@
 			default:
 				snprintf(state->message, SHPLOADERMSGLEN, _("Error: field %d has invalid or unknown field type (%d)"), i, state->types[i]);
 
+				/* clean up and return err */
 				SHPDestroyObject(obj);
 				stringbuffer_destroy(sbwarn);
 				stringbuffer_destroy(sb);
-
 				return SHPLOADERERR;
 			}
 
@@ -1638,6 +1641,10 @@
 					if ( rv == UTF8_BAD_RESULT )
 						free(utf8str);
 
+					/* clean up and return err */
+					SHPDestroyObject(obj);
+					stringbuffer_destroy(sbwarn);
+					stringbuffer_destroy(sb);
 					return SHPLOADERERR;
 				}
 				strncpy(val, utf8str, MAXVALUELEN);

Modified: trunk/raster/loader/raster2pgsql.c
===================================================================
--- trunk/raster/loader/raster2pgsql.c	2017-09-13 21:51:22 UTC (rev 15721)
+++ trunk/raster/loader/raster2pgsql.c	2017-09-14 13:52:25 UTC (rev 15722)
@@ -511,7 +511,7 @@
 init_rastinfo(RASTERINFO *info) {
 	info->srid = SRID_UNKNOWN;
 	info->srs = NULL;
-	memset(info->dim, 0, sizeof(double) * 2);
+	memset(info->dim, 0, sizeof(uint32_t) * 2);
 	info->nband_count = 0;
 	info->nband = NULL;
 	info->gdalbandtype = NULL;



More information about the postgis-tickets mailing list