Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit a9d366a

Browse files
author
Ikey Doherty
committed
Resolve linking issues - ensuring cve-check-tool works with full RELRO
This is currently the temporary path we'll use, as and when the packaging implementations switch to plugins, we can drop the current callback mechanism, abstract util.*, and query supported package types and then determine the plugin we'll use for the lifetime of this operation. Signed-off-by: Ikey Doherty <[email protected]>
1 parent 1bb3dab commit a9d366a

File tree

16 files changed

+36
-71
lines changed

16 files changed

+36
-71
lines changed

src/library/cve-check-tool.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,21 @@
1919

2020
#include "core.h"
2121

22+
/**
23+
* Distro implementations need to add packages to the interest list
24+
* before we will check them for CVEs. This will actually call back to
25+
* the self->examine function, and add the parsed package into the
26+
* current list.
27+
*
28+
* @param path Full legal path to the source package
29+
*/
30+
31+
typedef void (*cve_add_callback)(const char *);
32+
2233
/**
2334
* Function to yield all applicable sources.
2435
*/
25-
typedef void (*cve_locate_sources)(const char*, bool);
36+
typedef void (*cve_locate_sources)(const char*, bool, cve_add_callback);
2637

2738
/**
2839
* Determine if a package has already patched a vulnerability
@@ -72,13 +83,3 @@ typedef struct CveCheckTool {
7283
* Remotely exploitable
7384
*/
7485
#define ACCESS_VECTOR_NETWORK "NETWORK"
75-
76-
/**
77-
* Distro implementations need to add packages to the interest list
78-
* before we will check them for CVEs. This will actually call back to
79-
* the self->examine function, and add the parsed package into the
80-
* current list.
81-
*
82-
* @param path Full legal path to the source package
83-
*/
84-
void cve_add_package(const char *path);

src/library/util.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@
3232

3333
DEF_AUTOFREE(char, free)
3434

35-
bool find_sources(const char *path, package_match_func match, bool recurse)
35+
bool find_sources(const char *path, package_match_func match, bool recurse, cve_add_callback cb)
3636
{
3737
struct stat st = {.st_ino = 0};
3838
bool ret = false;
3939
DIR *dir = NULL;
4040
struct dirent *ent = NULL;
4141
char *fullp = NULL;
4242

43+
if (!cb) {
44+
return false;
45+
}
46+
4347
if (!match) {
4448
return false;
4549
}
@@ -61,14 +65,14 @@ bool find_sources(const char *path, package_match_func match, bool recurse)
6165
goto end;
6266
}
6367
if (!(cve_is_dir(fullp) && !recurse)) {
64-
find_sources(fullp, match, recurse);
68+
find_sources(fullp, match, recurse, cb);
6569
}
6670
free(fullp);
6771
}
6872
}
6973
} else if (S_ISREG(st.st_mode)) {
7074
if (match(path)) {
71-
cve_add_package(path);
75+
cb(path);
7276
}
7377
}
7478

src/library/util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ int64_t parse_xml_date(const char *date);
7878
* @param directory Base directory to recurse
7979
* @param match A function to determine "matching" source packages
8080
* @param recurse Whether we can recurse the given directory
81+
* @param cb A callback to execute when we encounter a matching package
8182
*/
82-
bool find_sources(const char *directory, package_match_func match, bool recurse);
83+
bool find_sources(const char *directory, package_match_func match, bool recurse, cve_add_callback cb);
8384

8485
/**
8586
* Implemented in a *similar* fashion to how g_autoptr is intended to

src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DEF_AUTOFREE(char, free)
5252
#define streq(x,y) strcmp(x,y) == 0
5353

5454

55-
static void cve_add_package_internal(struct source_package_t *pkg)
55+
void cve_add_package_internal(struct source_package_t *pkg)
5656
{
5757
GList *issues = NULL, *em = NULL;
5858
gchar *cur_id = NULL;
@@ -590,7 +590,7 @@ int main(int argc, char **argv)
590590
/* Attempt to add a single package.. */
591591
if (cve_is_dir(target)) {
592592
/* Recurse.. */
593-
self->locate(target, true);
593+
self->locate(target, true, &cve_add_package);
594594
} else {
595595
cve_add_package(target);
596596
}
@@ -677,7 +677,7 @@ int main(int argc, char **argv)
677677
goto cleanup;
678678
}
679679
}
680-
self->locate(path, false);
680+
self->locate(path, false, &cve_add_package);
681681
clean:
682682
free(buf);
683683
buf = NULL;

src/packaging/eopkg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ bool eopkg_is_package(const char *filename)
156156
return g_str_has_suffix((const gchar*)filename, "pspec.xml") || g_str_has_suffix((const gchar*)filename, "pspec_x86_64.xml");
157157
}
158158

159-
void eopkg_locate_sources(const char *directory, bool recurse)
159+
void eopkg_locate_sources(const char *directory, bool recurse, cve_add_callback cb)
160160
{
161-
find_sources(directory, &eopkg_is_package, recurse);
161+
find_sources(directory, &eopkg_is_package, recurse, cb);
162162
}

src/packaging/eopkg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ struct source_package_t *eopkg_inspect_pspec(const char *filename);
2424
bool eopkg_is_patched(struct source_package_t *pkg, char *id);
2525
bool eopkg_is_ignored(struct source_package_t *pkg, char *id);
2626

27-
void eopkg_locate_sources(const char *directory, bool recurse);
27+
void eopkg_locate_sources(const char *directory, bool recurse, cve_add_callback cb);
2828

2929
bool eopkg_is_package(const char *filename);

src/packaging/pkgbuild.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ bool pkgbuild_is_package(const char *filename)
111111
return g_str_has_suffix((const gchar*)filename, "PKGBUILD");
112112
}
113113

114-
void pkgbuild_locate_sources(const char *directory, bool recurse)
114+
void pkgbuild_locate_sources(const char *directory, bool recurse, cve_add_callback cb)
115115
{
116-
find_sources(directory, &pkgbuild_is_package, recurse);
116+
find_sources(directory, &pkgbuild_is_package, recurse, cb);
117117
}

src/packaging/pkgbuild.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ struct source_package_t *pkgbuild_inspect_spec(const char *filename);
2323

2424
bool pkgbuild_is_patched(struct source_package_t *pkg, char *id);
2525

26-
void pkgbuild_locate_sources(const char *directory, bool recurse);
26+
void pkgbuild_locate_sources(const char *directory, bool recurse, cve_add_callback cb);
2727

2828
bool pkgbuild_is_package(const char *filename);

src/packaging/rpm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ bool rpm_is_package(const char *filename)
330330
return g_str_has_suffix((const gchar*)filename, ".spec");
331331
}
332332

333-
void rpm_locate_sources(const char *directory, bool recurse)
333+
void rpm_locate_sources(const char *directory, bool recurse, cve_add_callback cb)
334334
{
335-
find_sources(directory, &rpm_is_package, recurse);
335+
find_sources(directory, &rpm_is_package, recurse, cb);
336336
}

src/packaging/rpm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ bool srpm_is_ignored(struct source_package_t *t, char *id);
3939
bool rpm_is_patched(struct source_package_t *pkg, char *id);
4040
bool rpm_is_ignored(struct source_package_t *pkg, char *id);
4141

42-
void rpm_locate_sources(const char *directory, bool recurse);
42+
void rpm_locate_sources(const char *directory, bool recurse, cve_add_callback cb);
4343

4444
bool rpm_is_package(const char *filename);

0 commit comments

Comments
 (0)