]>
Commit | Line | Data |
---|---|---|
fe377952 BS |
1 | commit b339543c6cac043f087b51fd859186e77f757f85 |
2 | Author: Nick Clifton <nickc@redhat.com> | |
3 | Date: Wed Aug 1 14:34:41 2018 +0100 | |
4 | ||
5 | Close resource leaks in the BFD library's plugin handler. | |
6 | ||
7 | PR 23460 | |
8 | * plugin.c (bfd_plugin_open_input): Close file descriptor if the | |
9 | call to fstat fails. | |
10 | (try_claim): Always close the file descriptor at the end of the | |
11 | function. | |
12 | (try_load_plugin): If a plugin has already been registered, then | |
13 | skip the dlopen and onload steps and go straight to claiming the | |
14 | file. If these is an error, close the plugin. | |
15 | ||
16 | diff --git a/bfd/ChangeLog b/bfd/ChangeLog | |
17 | index d3831b7a65..457c00e6bd 100644 | |
18 | --- a/bfd/ChangeLog | |
19 | +++ b/bfd/ChangeLog | |
20 | @@ -1,3 +1,14 @@ | |
21 | +2018-08-01 Zenith <zenith432@users.sourceforge.net> | |
22 | + | |
23 | + PR 23460 | |
24 | + * plugin.c (bfd_plugin_open_input): Close file descriptor if the | |
25 | + call to fstat fails. | |
26 | + (try_claim): Always close the file descriptor at the end of the | |
27 | + function. | |
28 | + (try_load_plugin): If a plugin has already been registered, then | |
29 | + skip the dlopen and onload steps and go straight to claiming the | |
30 | + file. If these is an error, close the plugin. | |
31 | + | |
32 | 2018-07-18 Nick Clifton <nickc@redhat.com> | |
33 | ||
34 | 2.31.1 Release point. | |
35 | diff --git a/bfd/plugin.c b/bfd/plugin.c | |
36 | index 7c5bba22c7..d9b9e2f174 100644 | |
37 | --- a/bfd/plugin.c | |
38 | +++ b/bfd/plugin.c | |
39 | @@ -124,7 +124,7 @@ message (int level ATTRIBUTE_UNUSED, | |
40 | } | |
41 | ||
42 | /* Register a claim-file handler. */ | |
43 | -static ld_plugin_claim_file_handler claim_file; | |
44 | +static ld_plugin_claim_file_handler claim_file = NULL; | |
45 | ||
46 | static enum ld_plugin_status | |
47 | register_claim_file (ld_plugin_claim_file_handler handler) | |
48 | @@ -186,8 +186,13 @@ bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file) | |
49 | if (iobfd == ibfd) | |
50 | { | |
51 | struct stat stat_buf; | |
52 | + | |
53 | if (fstat (file->fd, &stat_buf)) | |
54 | - return 0; | |
55 | + { | |
56 | + close(file->fd); | |
57 | + return 0; | |
58 | + } | |
59 | + | |
60 | file->offset = 0; | |
61 | file->filesize = stat_buf.st_size; | |
62 | } | |
63 | @@ -208,21 +213,24 @@ try_claim (bfd *abfd) | |
64 | file.handle = abfd; | |
65 | if (!bfd_plugin_open_input (abfd, &file)) | |
66 | return 0; | |
67 | - claim_file (&file, &claimed); | |
68 | - if (!claimed) | |
69 | - close (file.fd); | |
70 | + if (claim_file) | |
71 | + claim_file (&file, &claimed); | |
72 | + close (file.fd); | |
73 | return claimed; | |
74 | } | |
75 | ||
76 | static int | |
77 | try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p) | |
78 | { | |
79 | - void *plugin_handle; | |
80 | + void *plugin_handle = NULL; | |
81 | struct ld_plugin_tv tv[4]; | |
82 | int i; | |
83 | ld_plugin_onload onload; | |
84 | enum ld_plugin_status status; | |
85 | ||
86 | + if (claim_file) | |
87 | + goto have_claim_file; | |
88 | + | |
89 | *has_plugin_p = 0; | |
90 | ||
91 | plugin_handle = dlopen (pname, RTLD_NOW); | |
92 | @@ -257,6 +265,7 @@ try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p) | |
93 | if (status != LDPS_OK) | |
94 | goto err; | |
95 | ||
96 | +have_claim_file: | |
97 | *has_plugin_p = 1; | |
98 | ||
99 | abfd->plugin_format = bfd_plugin_no; | |
100 | @@ -272,6 +281,9 @@ try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p) | |
101 | return 1; | |
102 | ||
103 | err: | |
104 | + if (plugin_handle) | |
105 | + dlclose (plugin_handle); | |
106 | + register_claim_file (NULL); | |
107 | return 0; | |
108 | } | |
109 | ||
110 | @@ -362,7 +374,7 @@ load_plugin (bfd *abfd) | |
111 | int valid_plugin; | |
112 | ||
113 | full_name = concat (p, "/", ent->d_name, NULL); | |
114 | - if (stat(full_name, &s) == 0 && S_ISREG (s.st_mode)) | |
115 | + if (stat (full_name, &s) == 0 && S_ISREG (s.st_mode)) | |
116 | found = try_load_plugin (full_name, abfd, &valid_plugin); | |
117 | if (has_plugin <= 0) | |
118 | has_plugin = valid_plugin; |