Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#3608 closed defect (fixed)

Shp2pgsql invalid free when -W UTF-8

Reported by: mattzen Owned by: pramsey
Priority: medium Milestone: PostGIS 2.2.3
Component: postgis Version: 2.2.x
Keywords: Cc:

Description

Shp2pgsql crashes with an invalid free when passed a -W UTF-8 argument on the command line and the shapefile contains a code page. This is because shp2pgsql assumes that if the encoding is the string UTF-8 then the user has not overridden it. If the code page exists in the shapefile, the previous value of encoding is freed and, if it came from a command line argument, it is not heap-allocated.

The patch in https://github.com/postgis/postgis/pull/111 prevents the crash by strduping the command line argument, but doesn't address the wider issue of distinguishing a user-provided "UTF-8" from a default-supplied "UTF-8".

Change History (7)

comment:1 Changed 15 months ago by robe

Milestone: PostGIS 2.3.0PostGIS 2.2.3

comment:2 Changed 15 months ago by strk

Where's the assumption that "UTF-8" was not passed ? I'd rather remove that assumption by always strduping the default-supplied string.

comment:3 Changed 15 months ago by strk

I actually see the default encoding being strdup'ed already, in shp2pgsql-core.c, line 756:

  config->encoding = strdup(ENCODING_DEFAULT);                                  

The crash you're seeing might have another cause ?

comment:4 Changed 15 months ago by strk

Figured: the issue of distinguishing a user-provided from a default-supplied is unrelated to the crash. So I will committed your patch and invite you to file another ticket for that separate issue (which for the record affects using or not the shapefile-provided CodePage?, in shp2pgsql-core.c:870)

comment:5 Changed 15 months ago by strk

Resolution: fixed
Status: newclosed

In 15038:

Allocate memory for encoding argument, so it can be safely freed later.

Fixes #3608

Patch by Matt Amos <zerebubuth@…>

comment:6 Changed 15 months ago by strk

In 15039:

Allocate memory for encoding argument, so it can be safely freed later.

Fixes #3608 for 2.2 branch

Patch by Matt Amos <zerebubuth@…>

comment:7 Changed 15 months ago by strk

In 15040:

Allocate memory for encoding argument, so it can be safely freed later.

Fixes #3608 for 2.1 branch

Patch by Matt Amos <zerebubuth@…>

Note: See TracTickets for help on using tickets.