Skip to content

Commit

Permalink
g.proj: fix reading input WKT (OSGeo#1582)
Browse files Browse the repository at this point in the history
properly terminate input WKT string

Co-authored-by: Marc Jansen <[email protected]>
  • Loading branch information
metzm and marcjansen authored May 17, 2021
1 parent 6fa792c commit 05d9841
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions general/g.proj/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void set_authnamecode(OGRSpatialReferenceH);
int input_wkt(char *wktfile)
{
FILE *infd;
char buff[8000], *tmpwkt;
char buff[8192], *tmpwkt;
OGRSpatialReferenceH hSRS;
char *papszOptions[3];
int ret;
Expand All @@ -117,11 +117,17 @@ int input_wkt(char *wktfile)
infd = fopen(wktfile, "r");

if (infd) {
fread(buff, sizeof(buff), 1, infd);
size_t wktlen;

wktlen = fread(buff, 1, sizeof(buff), infd);
if (wktlen == sizeof(buff))
G_fatal_error(_("Input WKT definition is too long"));
if (ferror(infd))
G_fatal_error(_("Error reading WKT definition"));
else
fclose(infd);
/* terminate WKT string */
buff[wktlen] = '\0';
/* Get rid of newlines */
G_squeeze(buff);
}
Expand Down

0 comments on commit 05d9841

Please sign in to comment.