Skip to content

Commit 3d1ae68

Browse files
Merge pull request #72 from scanoss/5.4.5
5.4.5
2 parents 4155135 + 55fd1d6 commit 3d1ae68

File tree

13 files changed

+70
-136
lines changed

13 files changed

+70
-136
lines changed

inc/attributions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
#include "scanoss.h"
55

6-
int attribution_notices();
6+
int attribution_notices(char * components);
77

88
#endif

inc/match_list.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080

8181
#define MATCH_LIST_TOLERANCE 98.5
8282
typedef struct match_data_t match_data_t; /* Forward declaration */
83-
typedef struct scan_data_t scan_data_t; /* Forward declaration*/
8483

8584
/**
8685
* @brief Define a list of component_data_t

inc/mz.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33

44
#include "scanoss.h"
55

6-
void mz_file_contents(char *key, char * dbtable);
7-
void mz_get_key(struct mz_job *job, char *key);
6+
void mz_get_key(struct ldb_table kb, char *key);
87
#endif

inc/scan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ typedef struct scan_data_t
6262
int max_components_to_process; /* Max component to retrieve during snippet scanning */
6363
int max_snippets_to_show; //TODO
6464
int max_components_to_show; //TODO
65+
int max_matchmap_size;
6566
bool printed_succed;
6667
} scan_data_t;
6768

inc/scanoss.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define WFP_REC_LN 18
4141

4242
/* Log files */
43-
#define SCANOSS_VERSION "5.4.4"
43+
#define SCANOSS_VERSION "5.4.5"
4444
#define SCAN_LOG "/tmp/scanoss_scan.log"
4545
#define MAP_DUMP "/tmp/scanoss_map.dump"
4646
#define SLOW_QUERY_LOG "/tmp/scanoss_slow_query.log"
@@ -119,10 +119,6 @@ extern long microseconds_start;
119119
extern int map_rec_len;
120120
extern bool match_extensions;
121121

122-
/* File tracing -qi */
123-
extern uint8_t trace_id[MD5_LEN];
124-
extern bool trace_on;
125-
126122
/*component hint hold the last component matched/guessed */
127123
extern char * component_hint;
128124

@@ -141,6 +137,8 @@ extern struct ldb_table oss_license;
141137
extern struct ldb_table oss_attribution;
142138
extern struct ldb_table oss_cryptography;
143139
extern struct ldb_table oss_sources;
140+
extern struct ldb_table oss_notices;
141+
144142

145143
extern bool first_file;
146144
extern int max_vulnerabilities;

src/attributions.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,14 @@ uint8_t *data, uint32_t datalen, int iteration, void *ptr)
5959
memcpy(hexkey, data, MD5_LEN * 2);
6060
hexkey[MD5_LEN * 2] = 0;
6161

62-
/* Define mz_job values */
63-
char *src = calloc(MZ_MAX_FILE + 1, 1);
64-
uint8_t *zsrc = calloc((MZ_MAX_FILE + 1) * 2, 1);
65-
struct mz_job job;
66-
sprintf(job.path, "%s/oss/notices", ldb_root);
67-
memset(job.mz_id, 0, 2);
68-
job.mz = NULL;
69-
job.mz_ln = 0;
70-
job.id = NULL;
71-
job.ln = 0;
72-
job.data = src; // Uncompressed data
73-
job.data_ln = 0;
74-
job.zdata = zsrc; // Compressed data
75-
job.zdata_ln = 0;
76-
job.md5[MD5_LEN] = 0;
77-
job.key = NULL;
78-
7962
/* Print attribution notice header */
8063
char *component = (char *) ptr;
8164
printf("[%s]\n\n", component);
8265

8366
/* Print attribution notice */
84-
//mz_cat(&job, hexkey);
85-
mz_get_key(&job,hexkey);
67+
mz_get_key(oss_notices, hexkey);
8668
printf("\n");
8769

88-
free(src);
89-
free(zsrc);
90-
9170
return false;
9271
}
9372

@@ -304,11 +283,11 @@ void print_purl_attribution_notices(struct ldb_table oss_attributions, char * li
304283
* @brief //Validate the declared SBOM and print the attribution noticies in stdout
305284
* @return //TODO
306285
*/
307-
int attribution_notices()
286+
int attribution_notices(char * components)
308287
{
309288
char * licenses_json = notices_load_file();
310289
/* Validate SBOM */
311-
declared_components = get_components(optarg);
290+
declared_components = get_components(components);
312291
if (check_purl_attributions(oss_attribution, licenses_json) && !debug_on)
313292
/* Print attribution notices */
314293
print_purl_attribution_notices(oss_attribution, licenses_json);

src/help.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ Options:\n\
6565
-h Display this help and exit.\n\
6666
-d Save debugging information to disk (/tmp).\n\
6767
-q Produces no JSON output. Only debugging info via STDERR.\n\
68-
-i Trace specific file id when debugging (requires -q).\n\
6968
\n\
7069
Enviroment variables:\n\
7170
SCANOSS_MATCHMAP_MAX: define the snippet scanning match map size, %d by default.\n\

src/license.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ bool osadl_load_file(void)
117117
scanlog("Warning: Cannot find OSADL definition. Please check that %s is present\n", path);
118118
else
119119
result = true;
120-
121120
free(path);
122121
return result;
123122
}
@@ -172,10 +171,14 @@ int osadl_print_license(char *output, const char *license, bool more_keys_after)
172171
void print_osadl_license_data(char *license)
173172
{
174173
char output[MAX_FIELD_LN];
175-
osadl_print_license(output, license, false);
176-
printf("{\"%s\": {%s}}", license, output);
174+
int len = osadl_print_license(output, license, false);
175+
if (len >0)
176+
printf("{\"%s\": {%s}}", license, output);
177+
else
178+
printf("{\"%s\": {}}", license);
177179
}
178180

181+
179182
static char *json_from_license(uint32_t *crclist, char *buffer, char *license, int src, bool *first_record)
180183
{
181184
clean_license(license);

src/main.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ struct ldb_table oss_license;
5959
struct ldb_table oss_attribution;
6060
struct ldb_table oss_cryptography;
6161
struct ldb_table oss_sources;
62-
62+
struct ldb_table oss_notices;
6363
component_item *ignore_components;
6464
component_item *declared_components;
6565

66-
/* File tracing -qi */
67-
uint8_t trace_id[MD5_LEN];
68-
bool trace_on;
6966
bool lib_encoder_present = false;
7067
#define LDB_VER_MIN "4.1.0"
7168

@@ -168,6 +165,9 @@ void initialize_ldb_tables(char *name)
168165
snprintf(dbtable, MAX_ARGLN * 2, "%s/%s", oss_db_name, "sources");
169166
oss_sources = ldb_read_cfg(dbtable);
170167

168+
snprintf(dbtable, MAX_ARGLN * 2, "%s/%s", oss_db_name, "notices");
169+
oss_notices = ldb_read_cfg(dbtable);
170+
171171
kb_version_get();
172172
osadl_load_file();
173173

@@ -272,10 +272,6 @@ int main(int argc, char **argv)
272272
//global var initialization - it must be improved
273273
debug_on = false;
274274
quiet = false;
275-
276-
/* File tracing with -qi */
277-
trace_on = false;
278-
memset(trace_id, 0 ,16);
279275

280276
if (argc <= 1)
281277
{
@@ -295,7 +291,7 @@ int main(int argc, char **argv)
295291
int option;
296292
bool invalid_argument = false;
297293
char * ldb_db_name = NULL;
298-
while ((option = getopt(argc, argv, ":f:s:b:B:c:k:a:F:l:n:i:M:N:wtvhedqH")) != -1)
294+
while ((option = getopt(argc, argv, ":f:s:b:B:c:k:a:F:l:n:M:N:wtvhedqH")) != -1)
299295
{
300296
/* Check valid alpha is entered */
301297
if (optarg)
@@ -325,12 +321,17 @@ int main(int argc, char **argv)
325321

326322
case 'k':
327323
initialize_ldb_tables(ldb_db_name);
328-
mz_file_contents(optarg, oss_file.db);
324+
mz_get_key(oss_sources, optarg);
329325
exit(EXIT_SUCCESS);
330326
break;
331327

332328
case 'a':
333-
if (declared_components) printf("Cannot combine -s and -a\n");
329+
if (declared_components)
330+
{
331+
printf("Cannot combine -s and -a\n");
332+
break;
333+
}
334+
initialize_ldb_tables(ldb_db_name);
334335
exit(attribution_notices(optarg));
335336
break;
336337

@@ -340,6 +341,7 @@ int main(int argc, char **argv)
340341
break;
341342

342343
case 'l':
344+
initialize_ldb_tables(ldb_db_name);
343345
print_osadl_license_data(optarg);
344346
exit(EXIT_SUCCESS);
345347
break;
@@ -353,15 +355,6 @@ int main(int argc, char **argv)
353355
case 'N':
354356
scan_max_components = atol(optarg);
355357
break;
356-
case 'i':
357-
if (strlen(optarg) == (MD5_LEN * 2))
358-
{
359-
ldb_hex_to_bin(optarg, MD5_LEN * 2, trace_id);
360-
trace_on = true;
361-
}
362-
else fprintf(stderr, "Ignoring -i due to invalid length\n");
363-
break;
364-
365358
case 'w':
366359
force_wfp = true;
367360
break;
@@ -370,6 +363,7 @@ int main(int argc, char **argv)
370363
force_snippet_scan = true;
371364
break;
372365
case 't':
366+
initialize_ldb_tables(ldb_db_name);
373367
scan_benchmark();
374368
exit(EXIT_SUCCESS);
375369
break;
@@ -417,7 +411,7 @@ int main(int argc, char **argv)
417411
else
418412
{
419413
printf("'libhpsm.so' must be present in the system to execute this command\n");
420-
exit(1);
414+
exit(EXIT_FAILURE);
421415
}
422416
break;
423417
}

src/match.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ bool add_component_from_urlid(component_list_t *component_list, uint8_t *url_id,
399399
* @return false
400400
*/
401401

402-
file_recordset *files = NULL;
402+
static file_recordset *files = NULL;
403403

404404
bool component_from_file(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *raw_data, uint32_t datalen, int iteration, void *ptr)
405405
{

0 commit comments

Comments
 (0)