Skip to content

Commit

Permalink
fix: fix mapserver crash in some corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thefab committed Feb 5, 2019
1 parent 2f6efe6 commit 3a57dca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mapserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
2 changes: 2 additions & 0 deletions src/mapserverapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void mapserverapi_init() {
return;
}
__MAPSERVERAPI_TMPDIR = g_strdup("/tmp");
msSetup();
}

void mapserverapi_destroy() {
Expand All @@ -40,6 +41,7 @@ void mapserverapi_destroy() {
g_assert(__MAPSERVERAPI_INITIALIZED == TRUE);
}
msIO_resetHandlers();
msCleanup();
__MAPSERVERAPI_INITIALIZED = FALSE;
g_free(__MAPSERVERAPI_TMPDIR);
}
Expand Down
29 changes: 29 additions & 0 deletions src/test_mapserverapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3a57dca

Please sign in to comment.