From 0d50cc980df7b5b25be8ea29689cdfe08c587650 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 4 Sep 2017 09:51:14 +0200 Subject: PJ_hgridshift.c: fix memleak in initialization if grid loading fail. Same fix as commit e1ad1046873056ab3bfc3262bd343e8c874f395c. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3276. Credit to OSS Fuzz --- src/PJ_hgridshift.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/PJ_hgridshift.c') diff --git a/src/PJ_hgridshift.c b/src/PJ_hgridshift.c index 41c2b629..674b4da8 100644 --- a/src/PJ_hgridshift.c +++ b/src/PJ_hgridshift.c @@ -81,6 +81,8 @@ PJ *PROJECTION(hgridshift) { /* Was gridlist compiled properly? */ if ( pj_ctx_get_errno(P->ctx) ) { proj_log_error(P, "hgridshift: could not find required grid(s)."); + pj_dalloc(P->gridlist); + P->gridlist = NULL; return freeup_msg(P, -38); } -- cgit v1.2.3 From 6b07474e9427d53134e77f0bdf3ced7812d080c4 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Wed, 13 Sep 2017 13:27:14 +0200 Subject: Introduce PJ_DEFAULT_CTX constant that improves code readability --- src/PJ_hgridshift.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/PJ_hgridshift.c') diff --git a/src/PJ_hgridshift.c b/src/PJ_hgridshift.c index 674b4da8..4ee3fd42 100644 --- a/src/PJ_hgridshift.c +++ b/src/PJ_hgridshift.c @@ -110,18 +110,18 @@ int pj_hgridshift_selftest (void) { double dist; /* fail on purpose: +grids parameter is mandatory*/ - P = proj_create(0, "+proj=hgridshift"); + P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift"); if (0!=P) return 99; /* fail on purpose: open non-existing grid */ - P = proj_create(0, "+proj=hgridshift +grids=nonexistinggrid.gsb"); + P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift +grids=nonexistinggrid.gsb"); if (0!=P) return 999; /* Failure most likely means the grid is missing */ - P = proj_create (0, "+proj=hgridshift +grids=nzgd2kgrid0005.gsb +ellps=GRS80"); + P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift +grids=nzgd2kgrid0005.gsb +ellps=GRS80"); if (0==P) return 10; -- cgit v1.2.3 From 664577ced6a8e4074b1f53af82b5ae5d1d189eac Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Wed, 27 Sep 2017 13:56:34 +0200 Subject: Enable default destructor for all PJ objects. In most cases memory deallocation is completely removed from the code since it can be handled by the default destructor. In a few special cases a local destructor overrides the default destructor and makes sure that locally allocated memored is cleaned up correctly. Move all deallocation from pj_free to pj_default_destructor Rename pj_latlong.c to fit with the conventional format PJ_latlong.c - freeup was missed here due to wrong naming Clean up pj_init to avoid double deallocation; Also resolve #576 by adding z_0 and t_0 options in pj_init, while cleaning Add a prototype for dealloc_params Added missing errno.h include in pj_ctx.c Temporarily removing ob_tran from testvarious, to be sure that is where the trouble is Make PJ_ob_tran.c use proper initialization for the chained projection proj=ob_tran: make it clear, that we disallow ellipsoidal projections, and, for improved backwards compatibility, turns off default settings, which could inject unwanted ellipsoid definitions ... then also remove the ellipsoid definition from the testvarious test case - which is probably buggy anyway Work around cs2cs spherical init bug in testvarious; Forbid defs for ob_tran in pj_init --- src/PJ_hgridshift.c | 87 +++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 40 deletions(-) (limited to 'src/PJ_hgridshift.c') diff --git a/src/PJ_hgridshift.c b/src/PJ_hgridshift.c index 4ee3fd42..1b65b1bd 100644 --- a/src/PJ_hgridshift.c +++ b/src/PJ_hgridshift.c @@ -1,25 +1,9 @@ #define PJ_LIB__ #include "proj_internal.h" -#include +#include "projects.h" PROJ_HEAD(hgridshift, "Horizontal grid shift"); -static void *freeup_msg (PJ *P, int errlev) { - if (0==P) - return 0; - - if (0!=P->ctx) - pj_ctx_set_errno (P->ctx, errlev); - - return pj_dealloc(P); -} - - -static void freeup (PJ *P) { - freeup_msg (P, 0); - return; -} - static XYZ forward_3d(LPZ lpz, PJ *P) { PJ_TRIPLET point; @@ -67,25 +51,30 @@ static PJ_OBS reverse_obs(PJ_OBS obs, PJ *P) { } -PJ *PROJECTION(hgridshift) { - if (!pj_param(P->ctx, P->params, "tgrids").i) { - proj_log_error(P, "hgridshift: +grids parameter missing."); - return freeup_msg(P, -1); - } +#if 0 +static XY forward_xy(LP lp, PJ *P) { + PJ_TRIPLET point; + point.lp = lp; + point.lpz.z = 0; + point.xyz = forward_3d (point.lpz, P); + return point.xy; +} - /* Build gridlist. P->gridlist can be empty if +grids only ask for optional grids. */ - P->gridlist = pj_gridlist_from_nadgrids( P->ctx, pj_param(P->ctx, P->params, "sgrids").s, - &(P->gridlist_count) ); - /* Was gridlist compiled properly? */ - if ( pj_ctx_get_errno(P->ctx) ) { - proj_log_error(P, "hgridshift: could not find required grid(s)."); - pj_dalloc(P->gridlist); - P->gridlist = NULL; - return freeup_msg(P, -38); - } +static LP reverse_lp(XY xy, PJ *P) { + PJ_TRIPLET point; + point.xy = xy; + point.xyz.z = 0; + point.lpz = reverse_3d (point.xyz, P); + return point.lp; +} +#endif + + +PJ *PROJECTION(hgridshift) { + P->fwdobs = forward_obs; P->invobs = reverse_obs; P->fwd3d = forward_3d; @@ -96,6 +85,21 @@ PJ *PROJECTION(hgridshift) { P->left = PJ_IO_UNITS_RADIANS; P->right = PJ_IO_UNITS_RADIANS; + if (0==pj_param(P->ctx, P->params, "tgrids").i) { + proj_log_error(P, "hgridshift: +grids parameter missing."); + return pj_default_destructor (P, PJD_ERR_NO_ARGS); + } + + /* Build gridlist. P->gridlist can be empty if +grids only ask for optional grids. */ + P->gridlist = pj_gridlist_from_nadgrids( P->ctx, pj_param(P->ctx, P->params, "sgrids").s, + &(P->gridlist_count) ); + + /* Was gridlist compiled properly? */ + if ( pj_ctx_get_errno(pj_get_ctx(P)) ) { + proj_log_error(P, "hgridshift: could not find required grid(s)."); + return pj_default_destructor (P, PJD_ERR_FAILED_TO_LOAD_GRID); + } + return P; } @@ -111,24 +115,27 @@ int pj_hgridshift_selftest (void) { /* fail on purpose: +grids parameter is mandatory*/ P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift"); - if (0!=P) + if (0!=P) { + proj_destroy (P); return 99; - + } + /* fail on purpose: open non-existing grid */ - P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift +grids=nonexistinggrid.gsb"); - if (0!=P) + P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift +grids=@nonexistinggrid.gsb,anothernonexistinggrid.gsb"); + if (0!=P) { + proj_destroy (P); return 999; - - + } + /* Failure most likely means the grid is missing */ P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift +grids=nzgd2kgrid0005.gsb +ellps=GRS80"); if (0==P) return 10; - + a = proj_obs_null; a.coo.lpz.lam = PJ_TORAD(173); a.coo.lpz.phi = PJ_TORAD(-45); - + dist = proj_roundtrip (P, PJ_FWD, 1, a); if (dist > 0.00000001) return 1; -- cgit v1.2.3 From efa741bafb0f40d4d7b7f9138292f15965ed5d75 Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Fri, 6 Oct 2017 22:21:55 +0200 Subject: Switch proj_roundtrip to accept PJ_COORD, rather than PJ_OBS, and make it do proper geodesic distances for forward roundtrips --- src/PJ_hgridshift.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/PJ_hgridshift.c') diff --git a/src/PJ_hgridshift.c b/src/PJ_hgridshift.c index 1b65b1bd..0adc9e00 100644 --- a/src/PJ_hgridshift.c +++ b/src/PJ_hgridshift.c @@ -136,7 +136,7 @@ int pj_hgridshift_selftest (void) { a.coo.lpz.lam = PJ_TORAD(173); a.coo.lpz.phi = PJ_TORAD(-45); - dist = proj_roundtrip (P, PJ_FWD, 1, a); + dist = proj_roundtrip (P, PJ_FWD, 1, a.coo); if (dist > 0.00000001) return 1; -- cgit v1.2.3