From 3a57dca21c2e53515d60321319658916a693adf4 Mon Sep 17 00:00:00 2001 From: Fabien MARTY Date: Tue, 5 Feb 2019 15:31:38 +0100 Subject: [PATCH] fix: fix mapserver crash in some corner cases --- src/mapserver.h | 2 ++ src/mapserverapi.c | 2 ++ src/test_mapserverapi.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/mapserver.h b/src/mapserver.h index 51a1a8d..d710145 100644 --- a/src/mapserver.h +++ b/src/mapserver.h @@ -3,5 +3,7 @@ int msCGIHandler(const char *query_string, void **out_buffer, size_t *buffer_length); void msIO_resetHandlers(void); +int msSetup(void); +void msCleanup(void); #endif /* MAPSERVERAPI_MAPSERVER_H_ */ diff --git a/src/mapserverapi.c b/src/mapserverapi.c index 8607b78..cbe7851 100644 --- a/src/mapserverapi.c +++ b/src/mapserverapi.c @@ -32,6 +32,7 @@ void mapserverapi_init() { return; } __MAPSERVERAPI_TMPDIR = g_strdup("/tmp"); + msSetup(); } void mapserverapi_destroy() { @@ -40,6 +41,7 @@ void mapserverapi_destroy() { g_assert(__MAPSERVERAPI_INITIALIZED == TRUE); } msIO_resetHandlers(); + msCleanup(); __MAPSERVERAPI_INITIALIZED = FALSE; g_free(__MAPSERVERAPI_TMPDIR); } diff --git a/src/test_mapserverapi.c b/src/test_mapserverapi.c index c106e40..188b78d 100644 --- a/src/test_mapserverapi.c +++ b/src/test_mapserverapi.c @@ -52,6 +52,34 @@ void test_mapserverapi_invoke() mapserverapi_destroy(); } +void test_mapserverapi_double_invoke() +{ + mapserverapi_init(); + gchar *contents = get_mapfile_content("test"); + void *body; + gchar *content_type = NULL; + gsize body_length; + gboolean b = mapserverapi_invoke(contents, "LAYERS=ocean&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_xml&SRS=EPSG%3A4326&BBOX=-180.0,-90.0,180.0,90.0&WIDTH=500&HEIGHT=250", &body, &content_type, &body_length); + g_free(contents); + g_assert(b == TRUE); + g_file_set_contents("./testresult.png", body, body_length, NULL); + g_assert_cmpint(body_length, >, 1000); + g_assert_cmpstr(content_type, ==, "image/png"); + g_free(content_type); + mapserverapi_destroy(); + mapserverapi_init(); + contents = get_mapfile_content("test"); + content_type = NULL; + b = mapserverapi_invoke(contents, "LAYERS=ocean&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_xml&SRS=EPSG%3A4326&BBOX=-180.0,-90.0,180.0,90.0&WIDTH=500&HEIGHT=250", &body, &content_type, &body_length); + g_free(contents); + g_assert(b == TRUE); + g_file_set_contents("./testresult.png", body, body_length, NULL); + g_assert_cmpint(body_length, >, 1000); + g_assert_cmpstr(content_type, ==, "image/png"); + g_free(content_type); + mapserverapi_destroy(); +} + void test_mapserverapi_invoke2() { mapserverapi_init(); @@ -92,6 +120,7 @@ int main(int argc, char** argv) g_test_init (&argc, &argv, NULL); g_test_add_func("/mapserverapi/new_free", test_mapserverapi_init); g_test_add_func("/mapserverapi/invoke", test_mapserverapi_invoke); + g_test_add_func("/mapserverapi/double_invoke", test_mapserverapi_double_invoke); g_test_add_func("/mapserverapi/invoke2", test_mapserverapi_invoke2); g_test_add_func("/mapserverapi/invoke_to_file", test_mapserverapi_invoke_to_file); gint res = g_test_run();