[tracker/wip/carlosg/coverity-fixes: 2/16] libtracker-sparql: Check return values of XML writer functions
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/coverity-fixes: 2/16] libtracker-sparql: Check return values of XML writer functions
- Date: Sat, 23 Oct 2021 18:42:00 +0000 (UTC)
commit dd885f91c52e144c1474c330f5e9c4bddb15ac34
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Oct 23 11:39:46 2021 +0200
libtracker-sparql: Check return values of XML writer functions
CIDs: #1501112, #1501127, #1501130
src/libtracker-sparql/tracker-serializer-xml.c | 64 ++++++++++++++++++--------
1 file changed, 44 insertions(+), 20 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-serializer-xml.c b/src/libtracker-sparql/tracker-serializer-xml.c
index 057312dfb..d622dfdf2 100644
--- a/src/libtracker-sparql/tracker-serializer-xml.c
+++ b/src/libtracker-sparql/tracker-serializer-xml.c
@@ -78,15 +78,20 @@ serialize_up_to_position (TrackerSerializerXml *serializer_xml,
if (!serializer_xml->head_printed) {
xmlTextWriterStartDocument (serializer_xml->writer, "1.0", "UTF-8", NULL);
- xmlTextWriterStartElement (serializer_xml->writer, XML ("sparql"));
- xmlTextWriterStartElement (serializer_xml->writer, XML ("head"));
+ if (xmlTextWriterStartElement (serializer_xml->writer, XML ("sparql")) < 0)
+ goto error;
+
+ if (xmlTextWriterStartElement (serializer_xml->writer, XML ("head")) < 0)
+ goto error;
for (i = 0; i < tracker_sparql_cursor_get_n_columns (cursor); i++) {
const gchar *var;
var = tracker_sparql_cursor_get_variable_name (cursor, i);
- xmlTextWriterStartElement (serializer_xml->writer, XML ("variable"));
+
+ if (xmlTextWriterStartElement (serializer_xml->writer, XML ("variable")) < 0)
+ goto error;
if (var && *var) {
g_ptr_array_add (serializer_xml->vars,
@@ -96,15 +101,20 @@ serialize_up_to_position (TrackerSerializerXml *serializer_xml,
g_strdup_printf ("var%d", i + 1));
}
- xmlTextWriterWriteFormatAttribute (serializer_xml->writer,
- XML ("name"),
- "%s",
- (char *) g_ptr_array_index (serializer_xml->vars,
i));
+ if (xmlTextWriterWriteFormatAttribute (serializer_xml->writer,
+ XML ("name"),
+ "%s",
+ (char *) g_ptr_array_index
(serializer_xml->vars, i)) < 0)
+ goto error;
+
xmlTextWriterEndElement (serializer_xml->writer);
}
xmlTextWriterEndElement (serializer_xml->writer);
- xmlTextWriterStartElement (serializer_xml->writer, XML ("results"));
+
+ if (xmlTextWriterStartElement (serializer_xml->writer, XML ("results")) < 0)
+ goto error;
+
serializer_xml->head_printed = TRUE;
}
@@ -125,7 +135,8 @@ serialize_up_to_position (TrackerSerializerXml *serializer_xml,
serializer_xml->cursor_started = TRUE;
}
- xmlTextWriterStartElement (serializer_xml->writer, XML ("result"));
+ if (xmlTextWriterStartElement (serializer_xml->writer, XML ("result")) < 0)
+ goto error;
for (i = 0; i < tracker_sparql_cursor_get_n_columns (cursor); i++) {
const gchar *var, *str, *type = NULL, *datatype = NULL;
@@ -160,25 +171,31 @@ serialize_up_to_position (TrackerSerializerXml *serializer_xml,
var = g_ptr_array_index (serializer_xml->vars, i);
- xmlTextWriterStartElement (serializer_xml->writer, XML ("binding"));
- xmlTextWriterWriteFormatAttribute (serializer_xml->writer,
- XML ("name"),
- "%s",
- var);
+ if (xmlTextWriterStartElement (serializer_xml->writer, XML ("binding")) < 0)
+ goto error;
+
+ if (xmlTextWriterWriteFormatAttribute (serializer_xml->writer,
+ XML ("name"),
+ "%s",
+ var) < 0)
+ goto error;
- xmlTextWriterStartElement (serializer_xml->writer, XML (type));
+ if (xmlTextWriterStartElement (serializer_xml->writer, XML (type)) < 0)
+ goto error;
if (datatype) {
- xmlTextWriterWriteFormatAttribute (serializer_xml->writer,
- XML ("datatype"),
- "%s",
- datatype);
+ if (xmlTextWriterWriteFormatAttribute (serializer_xml->writer,
+ XML ("datatype"),
+ "%s",
+ datatype) < 0)
+ goto error;
}
str = tracker_sparql_cursor_get_string (cursor, i, NULL);
if (str) {
- xmlTextWriterWriteRaw (serializer_xml->writer, XML (str));
+ if (xmlTextWriterWriteRaw (serializer_xml->writer, XML (str)) < 0)
+ goto error;
}
xmlTextWriterEndElement (serializer_xml->writer);
@@ -189,6 +206,13 @@ serialize_up_to_position (TrackerSerializerXml *serializer_xml,
}
return TRUE;
+
+ error:
+ g_set_error_literal (error,
+ TRACKER_SPARQL_ERROR,
+ TRACKER_SPARQL_ERROR_INTERNAL,
+ "Error writing XML cursor content");
+ return FALSE;
}
static gssize
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]