Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#3608 closed defect (fixed)

Shp2pgsql invalid free when -W UTF-8

Reported by: Matt Amos 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 by robe, 8 years ago

Milestone: PostGIS 2.3.0PostGIS 2.2.3

comment:2 by strk, 8 years ago

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 by strk, 8 years ago

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 by strk, 8 years ago

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 by strk, 8 years ago

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 by strk, 8 years ago

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 by strk, 8 years ago

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.