Fix Coverity issues in common
authorColin Leroy <colin@colino.net>
Thu, 5 Jun 2014 15:58:08 +0000 (17:58 +0200)
committerColin Leroy <colin@colino.net>
Thu, 5 Jun 2014 15:58:08 +0000 (17:58 +0200)
src/common/smtp.c
src/common/smtp.h
src/common/socket.c
src/common/ssl.c
src/common/ssl_certificate.c
src/common/template.c
src/common/utils.c
src/common/xmlprops.c
src/send_message.c

index e540d1f..888b0b2 100644 (file)
@@ -586,7 +586,6 @@ static gint smtp_session_recv_msg(Session *session, const gchar *msg)
        case SMTP_READY:
                if (strstr(msg, "ESMTP"))
                        smtp_session->is_esmtp = TRUE;
-       case SMTP_CONNECTED:
 #ifdef USE_GNUTLS
                if (smtp_session->user || session->ssl_type != SSL_NONE ||
                    smtp_session->is_esmtp)
index 2e78b1f..706a097 100644 (file)
@@ -61,7 +61,6 @@ typedef enum
 typedef enum
 {
        SMTP_READY,
-       SMTP_CONNECTED,
        SMTP_HELO,
        SMTP_EHLO,
        SMTP_STARTTLS,
index 1fe2714..946293a 100644 (file)
@@ -238,7 +238,7 @@ void refresh_resolvers(void)
 #ifdef G_OS_WIN32
 #define SOCKET_IS_VALID(s)      ((s) != INVALID_SOCKET)
 #else
-#define SOCKET_IS_VALID(s)     TRUE
+#define SOCKET_IS_VALID(s)     (s != -1)
 #endif
 
 /* Due to the fact that socket under Windows are not represented by
index 1c7c335..c56a948 100644 (file)
@@ -275,6 +275,9 @@ gnutls_x509_crt_t *ssl_get_certificate_chain(gnutls_session_t session, gint *lis
        if (raw_cert_list && gnutls_certificate_type_get(session) == GNUTLS_CRT_X509) {
                int i = 0;
 
+               if (*list_len > 128)
+                       *list_len = 128;
+
                certs = g_malloc(sizeof(gnutls_x509_crt_t) * (*list_len));
 
                for(i = 0 ; i < (*list_len) ; i++) {
index 7fbfe5d..0a8b828 100644 (file)
@@ -553,6 +553,11 @@ static guint check_cert(SSLCertificate *cert)
                char *fingerprint;
 
                fp = g_fopen(chain_file, "r");
+               if (fp == NULL) {
+                       debug_print("fopen %s failed: %s\n", chain_file, strerror(errno));
+                       g_free(chain_file);
+                       return (guint)-1;
+               }
                if ((r = gnutls_import_X509_list_fp(fp, GNUTLS_X509_FMT_PEM, &chain, &max_certs)) < 0) {
                        debug_print("chain import failed: %s\n", gnutls_strerror(r));
                        fclose(fp);
@@ -1067,7 +1072,7 @@ gchar *ssl_certificate_get_subject_cn(SSLCertificate *cert)
 
        if(gnutls_x509_crt_get_dn_by_oid(cert->x509_cert, 
                GNUTLS_OID_X520_COMMON_NAME, 0, 0, subject_cn, &n))
-               strncpy(subject_cn, _("<not in certificate>"), BUFFSIZE);
+               return g_strdup(_("<not in certificate>"));
 
        return g_strdup(subject_cn);
 }
index 3fcbda2..b49b7d9 100644 (file)
@@ -280,8 +280,9 @@ static void template_write_config(GSList *tmpl_list)
                TRY_NO_CLOSE(fclose(fp) != EOF);
 
                if (new) {
-                       claws_unlink(filename);
-                       rename_force(new, filename);
+                       if (rename_force(new, filename) < 0) {
+                               FILE_OP_ERROR(new, "rename");
+                       }
                }
                g_free(new);
                g_free(filename);
index a592ce9..cca8c18 100644 (file)
@@ -3102,6 +3102,8 @@ FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename)
 #else
        *filename = g_strdup_printf("%s%cclaws.XXXXXX", dir, G_DIR_SEPARATOR);
        fd = mkstemp(*filename);
+       if (fd < 0)
+               return NULL;
 #endif
        return fdopen(fd, "w+");
 }
@@ -4777,10 +4779,17 @@ void mailcap_update_default(const gchar *type, const gchar *command)
        path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".mailcap", NULL);
        outpath = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".mailcap.new", NULL);
        FILE *fp = g_fopen(path, "rb");
-       FILE *outfp = g_fopen(outpath, "wb");
+       FILE *outfp = NULL;
        gchar buf[BUFFSIZE];
        gboolean err = FALSE;
 
+       if (!fp) {
+               g_free(path);
+               g_free(outpath);
+               return;
+       }
+
+       outfp = g_fopen(outpath, "wb");
        if (!outfp) {
                g_free(path);
                g_free(outpath);
@@ -5262,8 +5271,7 @@ size_t fast_strftime(gchar *buf, gint buflen, const gchar *format, struct tm *lt
                                format++;
                                break;
                        default:
-                               if (format && *format)
-                                       g_warning("format error (%c)", *format);
+                               g_warning("format error (%c)", *format);
                                *curpos = '\0';
                                return total_done;
                        }
index 0e0d3b8..dea67f4 100644 (file)
@@ -264,12 +264,12 @@ static void xmlprops_save_property(
 static void xmlprops_read_props( XmlProperty *props, XMLFile *file ) {
        GList *attr;
        gchar *name, *value;
-       gchar pName[ ATTR_BUFSIZE ];
-       gchar pValue[ ATTR_BUFSIZE ];
+       gchar *pName;
+       gchar *pValue;
 
        while( TRUE ) {
-               *pName = '\0';
-               *pValue = '\0';
+               pName = g_strdup("");
+               pValue = g_strdup("");
                if (! file->level ) break;
                xml_parse_next_tag( file );
                xml_get_current_tag( file );
@@ -279,15 +279,19 @@ static void xmlprops_read_props( XmlProperty *props, XMLFile *file ) {
                                name = ( ( XMLAttr * ) attr->data )->name;
                                value = ( ( XMLAttr * ) attr->data )->value;
                                if( strcmp( name, XMLS_ATTAG_NAME ) == 0 ) {
-                                       strcpy( pName, value );
+                                       g_free(pName);
+                                       pName = g_strdup( value );
                                }
                                else if( strcmp( name, XMLS_ATTAG_VALUE ) == 0 ) {
-                                       strcpy( pValue, value );
+                                       g_free(pValue);
+                                       pValue = g_strdup( value );
                                }
                                attr = g_list_next( attr );
                        }
                        xmlprops_save_property( props, pName, pValue );
                }
+               g_free(pName);
+               g_free(pValue);
        }
 }
 
index 80c0fb7..d048630 100644 (file)
@@ -475,7 +475,6 @@ static gint send_recv_message(Session *session, const gchar *msg, gpointer data)
 
        switch (smtp_session->state) {
        case SMTP_READY:
-       case SMTP_CONNECTED:
                return 0;
        case SMTP_HELO:
                g_snprintf(buf, sizeof(buf), _("Sending HELO..."));