[libgdata] [documents] Fix potential use of NULL variable in strcmp()



commit 4f2db5a119f2e4a7a86ca3b9b72c9d085b5152bc
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Aug 7 19:19:16 2010 +0100

    [documents] Fix potential use of NULL variable in strcmp()

 gdata/services/documents/gdata-documents-service.c |   53 ++++++++++----------
 1 files changed, 27 insertions(+), 26 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-service.c b/gdata/services/documents/gdata-documents-service.c
index 7989d83..45e1f5d 100644
--- a/gdata/services/documents/gdata-documents-service.c
+++ b/gdata/services/documents/gdata-documents-service.c
@@ -300,7 +300,7 @@ upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *docume
 	const gchar *slug = NULL, *content_type = NULL, *response_body;
 	gssize response_length;
 	GFileInfo *file_info = NULL;
-	GType new_document_type;
+	GType new_document_type = G_TYPE_INVALID;
 	GError *child_error = NULL;
 
 	/* Get some information about the file we're uploading */
@@ -320,35 +320,36 @@ upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *docume
 		 * Bug filed with Google: http://code.google.com/p/gdata-issues/issues/detail?id=1127 */
 		if (strcmp (content_type, "application/vnd.oasis.opendocument.spreadsheet") == 0)
 			content_type = "application/x-vnd.oasis.opendocument.spreadsheet";
+
+		if (document == NULL) {
+			/* Get the document type of the document which is being uploaded */
+			if (strcmp (content_type, "application/x-vnd.oasis.opendocument.spreadsheet") == 0 ||
+			    strcmp (content_type, "text/tab-separated-values") == 0 ||
+			    strcmp (content_type, "application/x-vnd.oasis.opendocument.spreadsheet") == 0 ||
+			    strcmp (content_type, "application/vnd.ms-excel") == 0) {
+				new_document_type = GDATA_TYPE_DOCUMENTS_SPREADSHEET;
+			} else if (strcmp (content_type, "application/msword") == 0 ||
+			           strcmp (content_type, "application/vnd.oasis.opendocument.text") == 0 ||
+			           strcmp (content_type, "application/rtf") == 0 ||
+			           strcmp (content_type, "text/html") == 0 ||
+			           strcmp (content_type, "application/vnd.sun.xml.writer") == 0 ||
+			           strcmp (content_type, "text/plain") == 0) {
+				new_document_type = GDATA_TYPE_DOCUMENTS_TEXT;
+			} else if (strcmp (content_type, "application/vnd.ms-powerpoint") == 0) {
+				new_document_type = GDATA_TYPE_DOCUMENTS_PRESENTATION;
+			} else {
+				g_set_error_literal (error, GDATA_DOCUMENTS_SERVICE_ERROR, GDATA_DOCUMENTS_SERVICE_ERROR_INVALID_CONTENT_TYPE,
+				                     _("The supplied document had an invalid content type."));
+				if (file_info != NULL)
+					g_object_unref (file_info);
+				return NULL;
+			}
+		}
 	}
 
 	/* Determine the type of the document we're uploading */
-	if (document == NULL) {
-		/* We get the document type of the document which is being uploaded */
-		if (strcmp (content_type, "application/x-vnd.oasis.opendocument.spreadsheet") == 0 ||
-		    strcmp (content_type, "text/tab-separated-values") == 0 ||
-		    strcmp (content_type, "application/x-vnd.oasis.opendocument.spreadsheet") == 0 ||
-		    strcmp (content_type, "application/vnd.ms-excel") == 0) {
-			new_document_type = GDATA_TYPE_DOCUMENTS_SPREADSHEET;
-		} else if (strcmp (content_type, "application/msword") == 0 ||
-		           strcmp (content_type, "application/vnd.oasis.opendocument.text") == 0 ||
-		           strcmp (content_type, "application/rtf") == 0 ||
-		           strcmp (content_type, "text/html") == 0 ||
-		           strcmp (content_type, "application/vnd.sun.xml.writer") == 0 ||
-		           strcmp (content_type, "text/plain") == 0) {
-			new_document_type = GDATA_TYPE_DOCUMENTS_TEXT;
-		} else if (strcmp (content_type, "application/vnd.ms-powerpoint") == 0) {
-			new_document_type = GDATA_TYPE_DOCUMENTS_PRESENTATION;
-		} else {
-			g_set_error_literal (error, GDATA_DOCUMENTS_SERVICE_ERROR, GDATA_DOCUMENTS_SERVICE_ERROR_INVALID_CONTENT_TYPE,
-			                     _("The supplied document had an invalid content type."));
-			if (file_info != NULL)
-				g_object_unref (file_info);
-			return NULL;
-		}
-	} else {
+	if (document != NULL)
 		new_document_type = G_OBJECT_TYPE (document);
-	}
 
 	/* We need streaming file I/O: GDataUploadStream */
 	output_stream = gdata_upload_stream_new (GDATA_SERVICE (self), method, upload_uri, GDATA_ENTRY (document), slug, content_type);



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