Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/scanoss.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 14 additions & 5 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions src/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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("<<<best list items: %d>>>\n", best_list->items);
if(!match_list_print(best_list, print_json_match, ","))
Expand All @@ -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++)
{
Expand All @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/snippet_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 31 additions & 2 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
};

Expand Down
Loading