diff --git a/inc/scanoss.h b/inc/scanoss.h index d5f6768..23ca700 100644 --- a/inc/scanoss.h +++ b/inc/scanoss.h @@ -33,7 +33,7 @@ #define WFP_LN 4 #define WFP_REC_LN 18 -#define SCANOSS_VERSION "5.4.22" +#define SCANOSS_VERSION "5.4.23" /* Log files */ #define SCAN_LOG "/tmp/scanoss_scan.log" diff --git a/inc/util.h b/inc/util.h index c0f89a2..183cdd7 100644 --- a/inc/util.h +++ b/inc/util.h @@ -59,7 +59,10 @@ bool valid_md5(char *str); char * json_remove_invalid_char(char * input); char * str_cat_realloc(char **a, char * b); - void flip_slashes(char *data); +void flip_slashes(char *data); + +char * scape_slashes(char *data); + void free_and_null(void ** pr); diff --git a/src/component.c b/src/component.c index 8b4bc02..52e0c28 100644 --- a/src/component.c +++ b/src/component.c @@ -253,7 +253,7 @@ bool fill_component(component_data_t *component, uint8_t *url_key, char *file_pa extract_csv(license, (char *)url_record, 5, sizeof(license)); extract_csv(purl, (char *)url_record, 6, sizeof(purl)); extract_csv(url, (char *)url_record, 7, sizeof(url)); - extract_csv(rank, (char *)url_record, 14, sizeof(rank)); //extracts the rank field if available + extract_csv(rank, (char *)url_record, -1, sizeof(rank)); //extracts the rank field if available /* Fill url stats if these are available*/ for (int i = 0; i < 5; i++) { char stat[16] = "\0"; diff --git a/src/file.c b/src/file.c index d56f9fe..02ae1e4 100644 --- a/src/file.c +++ b/src/file.c @@ -273,7 +273,7 @@ bool get_first_file(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *data, return false; *(char *)ptr = 0; - char *ext = file_extension((char *)file_data + MD5_LEN); + char *ext = file_extension((char *)file_data); if (ext) strcpy((char *) ptr, ext); diff --git a/src/parse.c b/src/parse.c index 4aa2570..a725d5b 100644 --- a/src/parse.c +++ b/src/parse.c @@ -293,11 +293,12 @@ char *skip_first_slash(char *data) } /** - * @brief Extracts the "n"th value from the comma separated "in" string - * @param out[out] parsed string - * @param in input buffer - * @param n col number - * @param limit string limit + * @brief Extracts the nth comma-separated field from the input string. + * Use n = -1 to extract the last field. + * @param out[out] output buffer where the extracted field is stored + * @param in input comma-separated string + * @param n 1-based field index to extract, or -1 for the last field + * @param limit maximum number of bytes to write to out (including null terminator) */ void extract_csv(char *out, char *in, int n, long limit) { @@ -310,6 +311,14 @@ void extract_csv(char *out, char *in, int n, long limit) limit--; // need an extra byte for chr(0) + /* n == -1: resolve to the last field */ + if (n == -1) + { + n = 1; + for (char *p = in; *p; p++) + if (*p == ',') n++; + } + char *tmp = in; int n_counter = 1; int out_ptr = 0; diff --git a/src/scan.c b/src/scan.c index 33c85ec..5a04163 100644 --- a/src/scan.c +++ b/src/scan.c @@ -371,8 +371,8 @@ int wfp_scan(char * path, int scan_max_snippets, int scan_max_components, bool a */ void output_matches_json(scan_data_t *scan) { - flip_slashes(scan->file_path); - + char * file_path = scape_slashes(scan->file_path); + /* Log slow query, if needed */ slow_query_log(scan); @@ -387,7 +387,7 @@ void output_matches_json(scan_data_t *scan) if (scan->matches_list_array_index > 1 && scan->max_snippets_to_process > 1) { engine_flags |= DISABLE_BEST_MATCH; - printf("\"%s\": {\"matches\":[", scan->file_path); + printf("\"%s\": {\"matches\":[", file_path); match_list_t *best_list = match_select_m_component_best(scan); scanlog("<<>>\n", best_list->items); if(!match_list_print(best_list, print_json_match, ",")) @@ -397,7 +397,7 @@ void output_matches_json(scan_data_t *scan) } else if (engine_flags & DISABLE_BEST_MATCH) { - printf("\"%s\": [", scan->file_path); + printf("\"%s\": [", file_path); bool first = true; for (int i = 0; i < scan->matches_list_array_index; i++) { @@ -415,21 +415,22 @@ void output_matches_json(scan_data_t *scan) /* prinf no match if the scan was evaluated as none */ // TODO must be unified with the "else" clause else if (scan->match_type == MATCH_NONE) { - printf("\"%s\": [{", scan->file_path); + printf("\"%s\": [{", file_path); print_json_nomatch(); } else if (scan->best_match && scan->best_match->component_list.items) { - printf("\"%s\": [{", scan->file_path); + printf("\"%s\": [{", file_path); print_json_match(scan->best_match); } else { - printf("\"%s\": [{", scan->file_path); + printf("\"%s\": [{", file_path); print_json_nomatch(); } json_close_file(scan); + free(file_path); engine_flags = engine_flags_aux; } diff --git a/src/snippet_selection.c b/src/snippet_selection.c index f3cd640..ea95e2d 100644 --- a/src/snippet_selection.c +++ b/src/snippet_selection.c @@ -62,8 +62,7 @@ bool snippet_extension_discard(match_data_t * match) return false; if (*ext1 && *ext2 && strcmp(ext1, ext2)) - // if (!known_src_extension(ext2)) - discard = true; + discard = true; if (discard) scanlog("Discarding matched extension %s for %s\n", ext2, ext1); diff --git a/src/util.c b/src/util.c index 93cdc21..f474559 100644 --- a/src/util.c +++ b/src/util.c @@ -53,6 +53,35 @@ data[i] = '/'; } + + /** @brief This script replaces \ with / + * @param data input/output buffer + */ +char * scape_slashes(char *data) +{ + if (!strchr(data, '\\')) + return strdup(data); + + int len = strlen(data); + char * out = calloc(1, len*2+1); + int j = 0; + + for (int i = 0; i < len; i++) + { + if (data[i] == '\\') + { + out[j++] = '\\'; + out[j++] = '\\'; + } + else + { + out[j] = data[i]; + j++; + } + } + return out; +} + /** * @brief Returns a pointer to field n in data * @param n field number @@ -386,8 +415,8 @@ int path_is_third_party(component_data_t *comp) "fixtures", "examples","assets", "runtime", "subprojects", "managed", "local_packages", "published", "libresources", "offloading", "compile", "release", "bundle", - "media", "documentation", "test", - "service","lib","dist", + "media","lib","documentation", "test", + "service","dist", "driver", "common","files" };