# HG changeset patch # User Guido Berhoerster # Date 1564491149 -7200 # Node ID ec5c1b653ee6fc81c63640e4bb268cb9f489e20e # Parent 956e97003bad49ae5bfb3d2441b695e14e371648 Prevent NULL pointer dereference Creating the end field may fail, thus try to allocate it in advance. diff -r 956e97003bad -r ec5c1b653ee6 pws-file.c --- a/pws-file.c Tue Jul 30 14:42:35 2019 +0200 +++ b/pws-file.c Tue Jul 30 14:52:29 2019 +0200 @@ -1146,6 +1146,13 @@ struct pws3_field *field = NULL; struct pws3_field *end_field = NULL; + end_field = pws3_field_create(1, PWS3_HEADER_FIELD_END); + if (end_field == NULL) { + pws_set_system_error(ctx->pws_file, PWS_ERR_NO_MEMORY, errno, + NULL); + goto out; + } + version_field = pws3_file_get_header_field(ctx->pws_file, PWS3_HEADER_FIELD_VERSION); if (version_field == NULL) { @@ -1180,7 +1187,6 @@ } } - end_field = pws3_field_create(1, PWS3_HEADER_FIELD_END); retval = write_field(ctx, end_field); if (retval != 0) { goto out;