diff options
author | netblue30 <netblue30@protonmail.com> | 2021-02-24 13:51:08 -0500 |
---|---|---|
committer | netblue30 <netblue30@protonmail.com> | 2021-02-24 13:51:08 -0500 |
commit | 74c8656e85db45ed84c99017903f87374e47c28f (patch) | |
tree | cf50163180aab743e47e24ab40f9daa5dcc90618 /src/fcopy/main.c | |
parent | Merge pull request #4004 from smitsohu/privatelib4 (diff) | |
download | firejail-74c8656e85db45ed84c99017903f87374e47c28f.tar.gz firejail-74c8656e85db45ed84c99017903f87374e47c28f.tar.zst firejail-74c8656e85db45ed84c99017903f87374e47c28f.zip |
fcopy: fixes for old compilers, cppcheck fixes (#3998)
Diffstat (limited to 'src/fcopy/main.c')
-rw-r--r-- | src/fcopy/main.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/fcopy/main.c b/src/fcopy/main.c index d863b537b..f69448b67 100644 --- a/src/fcopy/main.c +++ b/src/fcopy/main.c | |||
@@ -51,8 +51,9 @@ static int selinux_enabled = -1; | |||
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | // copy from firejail/selinux.c | 53 | // copy from firejail/selinux.c |
54 | static void selinux_relabel_path(const char *path, const char *inside_path) | 54 | static void selinux_relabel_path(const char *path, const char *inside_path) { |
55 | { | 55 | assert(path); |
56 | assert(inside_path); | ||
56 | #if HAVE_SELINUX | 57 | #if HAVE_SELINUX |
57 | char procfs_path[64]; | 58 | char procfs_path[64]; |
58 | char *fcon = NULL; | 59 | char *fcon = NULL; |
@@ -172,8 +173,8 @@ static void mkdir_attr(const char *fname, mode_t mode, uid_t uid, gid_t gid) { | |||
172 | } | 173 | } |
173 | } | 174 | } |
174 | 175 | ||
175 | static char *proc_pid_to_self(const char *target) | 176 | static char *proc_pid_to_self(const char *target) { |
176 | { | 177 | assert(target); |
177 | char *use_target = 0; | 178 | char *use_target = 0; |
178 | char *proc_pid = 0; | 179 | char *proc_pid = 0; |
179 | 180 | ||
@@ -182,10 +183,10 @@ static char *proc_pid_to_self(const char *target) | |||
182 | 183 | ||
183 | // target is under /proc/<PID>? | 184 | // target is under /proc/<PID>? |
184 | static const char proc[] = "/proc/"; | 185 | static const char proc[] = "/proc/"; |
185 | if (strncmp(use_target, proc, sizeof proc - 1)) | 186 | if (strncmp(use_target, proc, sizeof(proc) - 1)) |
186 | goto done; | 187 | goto done; |
187 | 188 | ||
188 | int digit = use_target[sizeof proc - 1]; | 189 | int digit = use_target[sizeof(proc) - 1]; |
189 | if (digit < '1' || digit > '9') | 190 | if (digit < '1' || digit > '9') |
190 | goto done; | 191 | goto done; |
191 | 192 | ||
@@ -206,11 +207,15 @@ static char *proc_pid_to_self(const char *target) | |||
206 | if (asprintf(&tmp, "%s%s", proc_self, use_target + pfix) != -1) { | 207 | if (asprintf(&tmp, "%s%s", proc_self, use_target + pfix) != -1) { |
207 | if (arg_debug) | 208 | if (arg_debug) |
208 | fprintf(stderr, "SYMLINK %s\n --> %s\n", use_target, tmp); | 209 | fprintf(stderr, "SYMLINK %s\n --> %s\n", use_target, tmp); |
209 | free(use_target), use_target = tmp; | 210 | free(use_target); |
211 | use_target = tmp; | ||
210 | } | 212 | } |
213 | else | ||
214 | errExit("asprintf"); | ||
211 | 215 | ||
212 | done: | 216 | done: |
213 | free(proc_pid); | 217 | if (proc_pid) |
218 | free(proc_pid); | ||
214 | return use_target; | 219 | return use_target; |
215 | } | 220 | } |
216 | 221 | ||