Skip to content

Commit 4c79d85

Browse files
Merge pull request #69 from scanoss/5.4.3
solve bug reading source files
2 parents 4d53e29 + 707e7cd commit 4c79d85

File tree

3 files changed

+61
-51
lines changed

3 files changed

+61
-51
lines changed

inc/scanoss.h

Lines changed: 2 additions & 2 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.2"
43+
#define SCANOSS_VERSION "5.4.3"
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"
@@ -140,7 +140,7 @@ extern struct ldb_table oss_dependency;
140140
extern struct ldb_table oss_license;
141141
extern struct ldb_table oss_attribution;
142142
extern struct ldb_table oss_cryptography;
143-
143+
extern struct ldb_table oss_sources;
144144

145145
extern bool first_file;
146146
extern int max_vulnerabilities;

src/main.c

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ struct ldb_table oss_dependency;
5858
struct ldb_table oss_license;
5959
struct ldb_table oss_attribution;
6060
struct ldb_table oss_cryptography;
61+
struct ldb_table oss_sources;
62+
6163
component_item *ignore_components;
6264
component_item *declared_components;
6365

@@ -66,6 +68,48 @@ uint8_t trace_id[MD5_LEN];
6668
bool trace_on;
6769
bool lib_encoder_present = false;
6870
#define LDB_VER_MIN "4.1.0"
71+
72+
void * lib_encoder_handle = NULL;
73+
bool lib_encoder_load()
74+
{
75+
#ifndef SCANOSS_ENCODER_VERSION
76+
/*set decode funtion pointer to NULL*/
77+
lib_encoder_handle = dlopen("libscanoss_encoder.so", RTLD_NOW);
78+
char * err;
79+
if ((err = dlerror()))
80+
{
81+
scanlog("Lib scanoss-encoder was not detected. %s\n", err);
82+
}
83+
84+
if (lib_encoder_handle)
85+
{
86+
scanlog("Lib scanoss-encoder present\n");
87+
decrypt_data = dlsym(lib_encoder_handle, "scanoss_decode_table");
88+
decrypt_mz = dlsym(lib_encoder_handle, "scanoss_decode_mz");
89+
encoder_version = dlsym(lib_encoder_handle, "scanoss_encoder_version");
90+
if ((err = dlerror()))
91+
{
92+
printf("%s - You may need to update libscanoss_encoder.so\n", err);
93+
exit(EXIT_FAILURE);
94+
}
95+
96+
char version[32] = "\0";
97+
encoder_version(version);
98+
scanlog("Lib scanoss-encoder version %s\n", version);
99+
return true;
100+
}
101+
decrypt_data = standalone_decrypt_data;
102+
decrypt_mz = NULL;
103+
return false;
104+
#else
105+
decrypt_data = scanoss_decode_table;
106+
decrypt_mz = scanoss_decode_mz;
107+
encoder_version = scanoss_encoder_version;
108+
scanlog("Using built-in encoder library v%s\n", SCANOSS_ENCODER_VERSION);
109+
return false;
110+
#endif
111+
}
112+
69113
/* Initialize tables for the DB name indicated (defaults to oss) */
70114
void initialize_ldb_tables(char *name)
71115
{
@@ -121,8 +165,13 @@ void initialize_ldb_tables(char *name)
121165
snprintf(dbtable, MAX_ARGLN * 2, "%s/%s", oss_db_name, "cryptography");
122166
oss_cryptography = ldb_read_cfg(dbtable);
123167

168+
snprintf(dbtable, MAX_ARGLN * 2, "%s/%s", oss_db_name, "sources");
169+
oss_sources = ldb_read_cfg(dbtable);
170+
124171
kb_version_get();
125172
osadl_load_file();
173+
174+
lib_encoder_present = lib_encoder_load();
126175
}
127176

128177
/**
@@ -212,45 +261,6 @@ uint64_t read_flags()
212261
return 0;
213262
}
214263

215-
216-
void * lib_encoder_handle = NULL;
217-
bool lib_encoder_load()
218-
{
219-
#ifndef SCANOSS_ENCODER_VERSION
220-
/*set decode funtion pointer to NULL*/
221-
lib_encoder_handle = dlopen("libscanoss_encoder.so", RTLD_NOW);
222-
char * err;
223-
if ((err = dlerror()))
224-
{
225-
scanlog("Lib scanoss-encoder was not detected. %s\n", err);
226-
}
227-
228-
if (lib_encoder_handle)
229-
{
230-
scanlog("Lib scanoss-encoder present\n");
231-
decrypt_data = dlsym(lib_encoder_handle, "scanoss_decode_table");
232-
decrypt_mz = dlsym(lib_encoder_handle, "scanoss_decode_mz");
233-
encoder_version = dlsym(lib_encoder_handle, "scanoss_encoder_version");
234-
if ((err = dlerror()))
235-
{
236-
printf("%s - You may need to update libscanoss_encoder.so\n", err);
237-
exit(EXIT_FAILURE);
238-
}
239-
return true;
240-
}
241-
decrypt_data = standalone_decrypt_data;
242-
decrypt_mz = NULL;
243-
return false;
244-
#else
245-
decrypt_data = scanoss_decode_table;
246-
decrypt_mz = scanoss_decode_mz;
247-
encoder_version = scanoss_encoder_version;
248-
scanlog("Using built-in encoder library v%s\n", SCANOSS_ENCODER_VERSION);
249-
return false;
250-
#endif
251-
}
252-
253-
254264
/**
255265
* @brief //TODO
256266
* @param argc //TODO
@@ -429,14 +439,6 @@ int main(int argc, char **argv)
429439
/* Perform scan */
430440
else
431441
{
432-
lib_encoder_present = lib_encoder_load();
433-
if (lib_encoder_present && debug_on)
434-
{
435-
char version[32] = "\0";
436-
encoder_version(version);
437-
scanlog("Lib encoder present - version %s\n", version);
438-
}
439-
440442
/* Validate target */
441443
char *arg_target = argv[argc-1];
442444
bool isfile = is_file(arg_target);

src/mz.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ void mz_get_key(struct mz_job *job, char *key)
5252
memcpy(mz_file_id, key, 4);
5353

5454
sprintf(mz_path, "%s/%s.mz", job->path, mz_file_id);
55+
if (oss_sources.definitions & LDB_TABLE_DEFINITION_ENCRYPTED)
56+
{
57+
if (decrypt_mz)
58+
strcat(mz_path, ".enc");
59+
else
60+
{
61+
fprintf(stderr, "Encoder lib not available. Install libscanoss_encoder.so and try again\n");
62+
exit(EXIT_FAILURE);
63+
}
64+
}
5565
scanlog("MZ path: %s \n", mz_path);
5666

57-
if (decrypt_mz && access(mz_path, F_OK) != 0)
58-
strcat(mz_path, ".enc");
5967
/* Save path and key on job */
6068
job->key = calloc(MD5_LEN, 1);
6169
ldb_hex_to_bin(key, MD5_LEN * 2, job->key);

0 commit comments

Comments
 (0)