input/saleae: reduce the format match routine's greed

Only return OK from the format match routine when either of the tested
conditions reliably matched. Return an error in all other cases. This
avoids that the Saleae module is "winning a contest" due to even the
weakest condition, and then is not able to handle the input file.
This commit is contained in:
Gerhard Sittig 2020-06-14 14:26:57 +02:00
parent d891892dc0
commit 9084c39608
1 changed files with 9 additions and 2 deletions

View File

@ -883,11 +883,14 @@ static int format_match(GHashTable *metadata, unsigned int *confidence)
static const char *zip_ext = ".sal"; static const char *zip_ext = ".sal";
static const char *bin_ext = ".bin"; static const char *bin_ext = ".bin";
gboolean matched;
const char *fn; const char *fn;
size_t fn_len, ext_len; size_t fn_len, ext_len;
const char *ext_pos; const char *ext_pos;
GString *buf; GString *buf;
matched = FALSE;
/* Weak match on the filename (when available). */ /* Weak match on the filename (when available). */
fn = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_FILENAME)); fn = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_FILENAME));
if (fn && *fn) { if (fn && *fn) {
@ -895,13 +898,16 @@ static int format_match(GHashTable *metadata, unsigned int *confidence)
ext_len = strlen(zip_ext); ext_len = strlen(zip_ext);
ext_pos = &fn[fn_len - ext_len]; ext_pos = &fn[fn_len - ext_len];
if (fn_len >= ext_len && g_ascii_strcasecmp(ext_pos, zip_ext) == 0) { if (fn_len >= ext_len && g_ascii_strcasecmp(ext_pos, zip_ext) == 0) {
if (SALEAE_WITH_SAL_SUPPORT) if (SALEAE_WITH_SAL_SUPPORT) {
*confidence = 10; *confidence = 10;
matched = TRUE;
}
} }
ext_len = strlen(bin_ext); ext_len = strlen(bin_ext);
ext_pos = &fn[fn_len - ext_len]; ext_pos = &fn[fn_len - ext_len];
if (fn_len >= ext_len && g_ascii_strcasecmp(ext_pos, bin_ext) == 0) { if (fn_len >= ext_len && g_ascii_strcasecmp(ext_pos, bin_ext) == 0) {
*confidence = 50; *confidence = 50;
matched = TRUE;
} }
} }
@ -913,13 +919,14 @@ static int format_match(GHashTable *metadata, unsigned int *confidence)
case FMT_LOGIC2_DIGITAL: case FMT_LOGIC2_DIGITAL:
case FMT_LOGIC2_ANALOG: case FMT_LOGIC2_ANALOG:
*confidence = 1; *confidence = 1;
matched = TRUE;
break; break;
default: default:
/* EMPTY */ /* EMPTY */
break; break;
} }
return SR_OK; return matched ? SR_OK : SR_ERR_DATA;
} }
static int init(struct sr_input *in, GHashTable *options) static int init(struct sr_input *in, GHashTable *options)