From e0cdcc67f54595d61b1df3568b01ee927f750496 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sun, 24 Jun 2007 08:48:01 +0000 Subject: [PATCH] Add more checks for sane structures. Fixes another crash of #450276. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16210 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/import-export/import-backend.c | 56 +++++++++++++------------- src/import-export/ofx/gnc-ofx-import.c | 2 +- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/import-export/import-backend.c b/src/import-export/import-backend.c index 9cde7dbd7e..85036ccd78 100644 --- a/src/import-export/import-backend.c +++ b/src/import-export/import-backend.c @@ -584,13 +584,13 @@ static void split_find_match (GNCImportTransInfo * trans_info, time_t match_time, download_time; int datediff_day; Transaction *new_trans = gnc_import_TransInfo_get_trans (trans_info); + Split *new_trans_fsplit = gnc_import_TransInfo_get_fsplit (trans_info); /* Matching heuristics */ /* Amount heuristics */ downloaded_split_amount = - gnc_numeric_to_double - (xaccSplitGetAmount(gnc_import_TransInfo_get_fsplit (trans_info))); + gnc_numeric_to_double (xaccSplitGetAmount(new_trans_fsplit)); /*DEBUG(" downloaded_split_amount=%f", downloaded_split_amount);*/ match_split_amount = gnc_numeric_to_double(xaccSplitGetAmount(split)); /*DEBUG(" match_split_amount=%f", match_split_amount);*/ @@ -598,7 +598,7 @@ static void split_find_match (GNCImportTransInfo * trans_info, /* bug#347791: Doubly type shouldn't be compared for exact equality, so we're using fabs() instead. */ /*if (gnc_numeric_equal(xaccSplitGetAmount - (gnc_import_TransInfo_get_fsplit (trans_info)), + (new_trans_fsplit), xaccSplitGetAmount(split))) -- gnc_numeric_equal is an expensive function call */ { @@ -655,15 +655,15 @@ static void split_find_match (GNCImportTransInfo * trans_info, split anyway and skip the rest of the tests.) */ } - /* Check number heuristics */ - if(strlen(xaccTransGetNum(new_trans))!=0) - { + /* Check number heuristics */ + { + const char *new_trans_str = xaccTransGetNum(new_trans); + if (new_trans_str && strlen(new_trans_str) != 0) { long new_trans_number, split_number; - const gchar *new_trans_str, *split_str; + const gchar *split_str; char *endptr; gboolean conversion_ok = TRUE; - new_trans_str = xaccTransGetNum (new_trans); /* To distinguish success/failure after strtol call */ errno = 0; new_trans_number = strtol(new_trans_str, &endptr, 10); @@ -692,20 +692,19 @@ static void split_find_match (GNCImportTransInfo * trans_info, prob -= 2; } } - + } + /* Memo heuristics */ - if(strlen(xaccSplitGetMemo(gnc_import_TransInfo_get_fsplit (trans_info)))!=0) - { - if((strcmp(xaccSplitGetMemo(gnc_import_TransInfo_get_fsplit (trans_info)), - xaccSplitGetMemo(split)) - ==0)) + { + const char *memo = xaccSplitGetMemo(new_trans_fsplit); + if (memo && strlen(memo) != 0) { + if (safe_strcmp(memo, xaccSplitGetMemo(split)) == 0) { /* An exact match of memo gives a +2 */ prob = prob+2; /* DEBUG("heuristics: probability + 2 (memo)"); */ } - else if((strncmp(xaccSplitGetMemo(gnc_import_TransInfo_get_fsplit (trans_info)), - xaccSplitGetMemo(split), + else if((strncmp(memo, xaccSplitGetMemo(split), strlen(xaccSplitGetMemo(split))/2) ==0)) { @@ -717,19 +716,21 @@ static void split_find_match (GNCImportTransInfo * trans_info, /*DEBUG("heuristics: probability + 1 (memo)"); */ } } + } - /* Description heuristics */ - if(strlen(xaccTransGetDescription(new_trans))!=0) - { - if((strcmp(xaccTransGetDescription (new_trans), - xaccTransGetDescription(xaccSplitGetParent(split))) - ==0)) + /* Description heuristics */ + { + const char *descr = xaccTransGetDescription(new_trans); + if (descr && strlen(descr) != 0) { + if (safe_strcmp(descr, + xaccTransGetDescription(xaccSplitGetParent(split))) + ==0) { /*An exact match of Description gives a +2 */ prob = prob+2; /*DEBUG("heuristics: probability + 2 (description)");*/ } - else if((strncmp(xaccTransGetDescription (new_trans), + else if((strncmp(descr, xaccTransGetDescription (xaccSplitGetParent(split)), strlen(xaccTransGetDescription (new_trans))/2) ==0)) @@ -742,17 +743,18 @@ static void split_find_match (GNCImportTransInfo * trans_info, /*DEBUG("heuristics: probability + 1 (description)"); */ } } + } /*Online id punishment*/ - if ((gnc_import_get_trans_online_id(xaccSplitGetParent(split))!=NULL) && - (strlen(gnc_import_get_trans_online_id(xaccSplitGetParent(split)))>0)) - { +/* if ((gnc_import_get_trans_online_id(xaccSplitGetParent(split))!=NULL) && */ +/* (strlen(gnc_import_get_trans_online_id(xaccSplitGetParent(split)))>0)) */ +/* { */ /* If the pref is to show match even with online ID's, puninsh the transaction with online id */ /* DISABLED, it's the wrong solution to the problem. benoitg, 24/2/2003 */ /*prob = prob-3;*/ - } +/* } */ /* Is the probability high enough? Otherwise do nothing and return. */ if(prob < display_threshold) diff --git a/src/import-export/ofx/gnc-ofx-import.c b/src/import-export/ofx/gnc-ofx-import.c index 1b7754d14e..9454078305 100644 --- a/src/import-export/ofx/gnc-ofx-import.c +++ b/src/import-export/ofx/gnc-ofx-import.c @@ -302,7 +302,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u } xaccTransSetNotes(transaction, notes); g_free(notes); - if( data.account_ptr->currency_valid == true) + if ( data.account_ptr && data.account_ptr->currency_valid ) { DEBUG("Currency from libofx: %s",data.account_ptr->currency); currency = gnc_commodity_table_lookup( gnc_get_current_commodities (),