[geocode-glib/wip/wjt/30-nominatim-soup3] nominatim: Validate response as UTF-8




commit 1743789f6dfe7dd69bac345ee2a5e23a2f98279b
Author: Will Thompson <wjt endlessos org>
Date:   Sat Aug 6 20:49:54 2022 +0100

    nominatim: Validate response as UTF-8
    
    Previously, the bytes read from the server's response were assumed to be
    valid UTF-8.  Particularly since we are copying it anyway, validate it
    at the same time.
    
    (In practice this is probably a non-issue because it just ends up
    getting passed to json_parser_load_from_data() which validates its input
    as UTF-8 anyway.)

 geocode-glib/geocode-nominatim.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/geocode-glib/geocode-nominatim.c b/geocode-glib/geocode-nominatim.c
index d18e71f..4f62460 100644
--- a/geocode-glib/geocode-nominatim.c
+++ b/geocode-glib/geocode-nominatim.c
@@ -910,7 +910,7 @@ on_query_data_loaded (GObject      *object,
        } else {
                gsize size = 0;
                gconstpointer data = g_bytes_get_data (body, &size);
-               gchar *contents = g_strndup (data, size);
+               gchar *contents = g_utf8_make_valid (data, size);
 
                _geocode_glib_cache_save (query, contents);
                g_task_return_pointer (task, contents, g_free);
@@ -933,7 +933,7 @@ on_query_data_loaded (SoupSession *session,
                                         "%s",
                                         query->reason_phrase ? query->reason_phrase : "Query failed");
        else {
-               contents = g_strndup (query->response_body->data, query->response_body->length);
+               contents = g_utf8_make_valid (query->response_body->data, query->response_body->length);
                _geocode_glib_cache_save (query, contents);
                g_task_return_pointer (task, contents, g_free);
        }
@@ -1074,7 +1074,7 @@ geocode_nominatim_query (GeocodeNominatim  *self,
                } else {
                        gsize size = 0;
                        gconstpointer data = g_bytes_get_data (body, &size);
-                       contents = g_strndup (data, size);
+                       contents = g_utf8_make_valid (data, size);
 
                        _geocode_glib_cache_save (soup_query, contents);
                }
@@ -1084,7 +1084,7 @@ geocode_nominatim_query (GeocodeNominatim  *self,
                                             soup_query->reason_phrase ? soup_query->reason_phrase : "Query 
failed");
                        contents = NULL;
                } else {
-                       contents = g_strndup (soup_query->response_body->data, 
soup_query->response_body->length);
+                       contents = g_utf8_make_valid (soup_query->response_body->data, 
soup_query->response_body->length);
                        _geocode_glib_cache_save (soup_query, contents);
                }
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]