diff options
| author | Aaron Puchert <aaronpuchert@alice-dsl.net> | 2017-10-19 14:04:35 +0200 |
|---|---|---|
| committer | Thomas Knudsen <busstoptaktik@users.noreply.github.com> | 2017-10-19 14:04:35 +0200 |
| commit | 3ef083767eaf975399243246605fddc40cc097f9 (patch) | |
| tree | b2c45357d24f2a13850bbc46fea781a583436fc0 /src/pj_datum_set.c | |
| parent | fe3e7fd972682e3fec6926a7cc66ededeab55701 (diff) | |
| download | PROJ-3ef083767eaf975399243246605fddc40cc097f9.tar.gz PROJ-3ef083767eaf975399243246605fddc40cc097f9.zip | |
Prevent crashes and leaks on allocation failure (#606)
* Prevent crashes and leaks on allocation failure
Memory allocation can fail. We need to gracefully handle this case and
prevent dereferencing null pointers.
* Make NULL checks consistent within a file
* Properly report allocation errors
* Improve cleanup in pj_gc_reader.c
* Implement pj_strdup and use instead of strdup
The function strdup is not part of ANSI C 89, but a POSIX extension.
Therefore we can not rely on it being available on all platforms.
Diffstat (limited to 'src/pj_datum_set.c')
| -rw-r--r-- | src/pj_datum_set.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/pj_datum_set.c b/src/pj_datum_set.c index 3fba68f4..c2fb1608 100644 --- a/src/pj_datum_set.c +++ b/src/pj_datum_set.c @@ -25,6 +25,7 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include <errno.h> #include <projects.h> #include <string.h> @@ -101,7 +102,11 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef) const char *date; projdef->datum_type = PJD_GRIDSHIFT; - projdef->catalog_name = strdup(catalog); + projdef->catalog_name = pj_strdup(catalog); + if (!projdef->catalog_name) { + pj_ctx_set_errno(ctx, ENOMEM); + return 1; + } date = pj_param(ctx, pl, "sdate").s; if( date != NULL) |
