From ac1408af5fde896cf0ed331063f99434d835f054 Mon Sep 17 00:00:00 2001 From: Salvador Cuñat Date: Thu, 1 Aug 2019 23:50:26 +0200 Subject: [smtk-import] avoid infinite loop on index failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As Berthold points out, a failure to match the site or location index will result in an infinite loop with previous patch. With this one the loop will end after reading the last table row even if no idx is matched. But ... If we asume this situation is possible the retrieved data would be wrong, and ending the function without filling the site structure is mandatory too. Signed-off-by: Salvador Cuñat --- smtk-import/smartrak.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c index 4ed87a646..5382d3e6c 100644 --- a/smtk-import/smartrak.c +++ b/smtk-import/smartrak.c @@ -321,7 +321,7 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **lo MdbTableDef *table; MdbColumn *col[MDB_MAX_COLS]; char *bound_values[MDB_MAX_COLS]; - int i; + int i, rc; uint32_t d; struct dive_site *ds; location_t loc; @@ -333,10 +333,11 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **lo table = smtk_open_table(mdb, "Site", col, bound_values); if (!table) return; - do { - mdb_fetch_row(table); - } while (strcasecmp(col[0]->bind_ptr, idx)); + rc = mdb_fetch_row(table); + } while (strcasecmp(col[0]->bind_ptr, idx) && rc != 0); + if (rc == 0) + return; loc_idx = copy_string(col[2]->bind_ptr); site = copy_string(col[1]->bind_ptr); loc = create_location(strtod(col[6]->bind_ptr, NULL), strtod(col[7]->bind_ptr, NULL)); @@ -362,8 +363,10 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **lo table = smtk_open_table(mdb, "Location", col, bound_values); mdb_rewind_table(table); do { - mdb_fetch_row(table); - } while (strcasecmp(col[0]->bind_ptr, loc_idx)); + rc =mdb_fetch_row(table); + } while (strcasecmp(col[0]->bind_ptr, loc_idx) && rc != 0); + if (rc == 0) + return; /* * Create a string for Subsurface's dive site structure with coordinates -- cgit v1.2.3-70-g09d2