Opened 15 years ago

Closed 15 years ago

#3136 closed defect (fixed)

WFS Client seg fault (OGR layer not opened)

Reported by: jimk Owned by: assefa
Priority: normal Milestone: 5.6 release
Component: WFS Client Version: svn-trunk (development)
Severity: normal Keywords:
Cc:

Description

I am seeing an seg-fault when trying to access a WFS layer in mapserver (CONNECTIONTYPE WFS).

The seg-fault is at msOGRFileGetItems because psInfo (same as layerinfo) is NULL.

(gdb) bt #0 0x00000000004679f2 in msOGRFileGetItems (layer=0x70d450, psInfo=0x0) at mapogr.cpp:1651 #1 0x000000000046c157 in msOGRLayerGetItems (layer=0x70d450) at mapogr.cpp:2275 #2 0x00000000004e3fa3 in msWFSLayerGetItems (layer=0x70d450) at mapwfslayer.c:919 #3 0x000000000046cd7c in msLayerGetItems (layer=0x70d450) at maplayer.c:246 #4 0x000000000046d27e in msLayerWhichItems (layer=0x70d450, get_all=0, metadata=0x0) at maplayer.c:385 #5 0x0000000000480c65 in msDrawVectorLayer (map=0x6f3fb0, layer=0x70d450, image=0x70d3f0) at mapdraw.c:929 #6 0x0000000000480778 in msDrawLayer (map=0x6f3fb0, layer=0x70d450, image=0x70d3f0) at mapdraw.c:812 #7 0x000000000047f647 in msDrawMap (map=0x6f3fb0, querymap=0) at mapdraw.c:458 #8 0x00000000004147f3 in main (argc=2, argv=0x7fffdf89daa8) at mapserv.c:1414

layer->layerinfo is NULL because the OGR layer was never opened. The OGR layer was never opened because msWFSLayerOpen checks if layer->wfslayerinfo is NULL and if it isn't assumes the layer is fully initialized. But this isn't the case because msPrepareWFSLayerRequest is pre-opening the layer thus setting up layer->wfslayerinfo but doesn't call msWFSLayerWhichShapes to initialize the OGR layer.

My fix: Add a NULL pointer check to msOGRFileGetItems. Add a check to msWFSOpenLayer to see if layer->layerinfo is set when layer->wfslayerinfo is set. If layerinfo isn't set it calls msWFSWhichShapes to setup the OGR layer, otherwise it does nothing (as before.)

Attachments (1)

wfs-r9354.patch (1.1 KB ) - added by jimk 15 years ago.

Download all attachments as: .zip

Change History (5)

by jimk, 15 years ago

Attachment: wfs-r9354.patch added

comment:1 by jimk, 15 years ago

Just noticed another code path to the same problem (OGR Layer isn't opened) that isn't covered in the above patch. It occurs when msWFSLayerWhichShapes finds no shapes and returns MS_DONE instead of finishing and calling msOGRLayerOpen/msOGRLayerWhichShapes.

comment:2 by assefa, 15 years ago

Owner: changed from mapserverbugs to assefa

looking into this before beta2

comment:3 by jimk, 15 years ago

I also found what appears to be a race condition in the creation of the temporary GML file. The problem occurs when bPostRequest is false and two similar requests occur at nearly the same time (in my case one with mode=map and an identical one but with mode=nquery&searchmap=true). Then both requests use the same filename for the temporary file which causes one of the two requests to fail. The problem code is in mapwfslayer.c lines 649-659.

Forcing the condition of the if statement to true eliminates the problem, but probably eliminates some caching efforts.

    if (bPostRequest) // expect race condition between two requests causing second to fail with same URL if bPostRequest is false
    {
        char *pszPostTmpName = NULL;
        pszPostTmpName = (char *)malloc(sizeof(char)*(strlen(pszURL)+128));
        sprintf(pszPostTmpName,"%s%ld%d",
                pszURL, (long)time(NULL), (int)getpid());
        pszHashFileName = msHashString(pszPostTmpName);
        free(pszPostTmpName);
    }
    else
      pszHashFileName = msHashString(pszURL);

comment:4 by assefa, 15 years ago

Resolution: fixed
Status: newclosed

applied patch in r9356. Thanks

I moved the 2nd bug on race condition to #3137

Note: See TracTickets for help on using tickets.