ishcherb / rpms / abrt

Forked from rpms/abrt 6 years ago
Clone
fa19501
From ce7d0e05de76ae5383bcdfdba3ffa8816ffb63bd Mon Sep 17 00:00:00 2001
fa19501
From: Jakub Filak <jfilak@redhat.com>
fa19501
Date: Wed, 13 May 2015 13:05:48 +0200
fa19501
Subject: [PATCH] ccpp: make saving of binary more robust
fa19501
fa19501
Do not override existing files (defend against hard | symbolic link
fa19501
attacks) and use the *at functions (defend against race conditions).
fa19501
fa19501
Signed-off-by: Jakub Filak <jfilak@redhat.com>
fa19501
---
fa19501
 src/hooks/abrt-hook-ccpp.c | 12 +++++-------
fa19501
 1 file changed, 5 insertions(+), 7 deletions(-)
fa19501
fa19501
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
fa19501
index 8f3b2b0..9d9f549 100644
fa19501
--- a/src/hooks/abrt-hook-ccpp.c
fa19501
+++ b/src/hooks/abrt-hook-ccpp.c
fa19501
@@ -379,7 +379,7 @@ static int test_configuration(bool setting_SaveFullCore, bool setting_CreateCore
fa19501
     return 0;
fa19501
 }
fa19501
 
fa19501
-int save_crashing_binary(pid_t pid, const char *dest_path, uid_t uid, gid_t gid)
fa19501
+static int save_crashing_binary(pid_t pid, struct dump_dir *dd)
fa19501
 {
fa19501
     char buf[sizeof("/proc/%lu/exe") + sizeof(long)*3];
fa19501
 
fa19501
@@ -391,15 +391,15 @@ int save_crashing_binary(pid_t pid, const char *dest_path, uid_t uid, gid_t gid)
fa19501
         return 0;
fa19501
     }
fa19501
 
fa19501
-    int dst_fd = open(dest_path, O_WRONLY | O_CREAT | O_TRUNC, DEFAULT_DUMP_DIR_MODE);
fa19501
+    int dst_fd = openat(dd->dd_fd, FILENAME_BINARY, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, DEFAULT_DUMP_DIR_MODE);
fa19501
     if (dst_fd < 0)
fa19501
     {
fa19501
-        log_notice("Failed to create file '%s'", dest_path);
fa19501
+        log_notice("Failed to create file '"FILENAME_BINARY"' at '%s'", dd->dd_dirname);
fa19501
         close(src_fd_binary);
fa19501
         return -1;
fa19501
     }
fa19501
 
fa19501
-    IGNORE_RESULT(fchown(dst_fd, uid, gid));
fa19501
+    IGNORE_RESULT(fchown(dst_fd, dd->dd_uid, dd->dd_gid));
fa19501
 
fa19501
     off_t sz = copyfd_eof(src_fd_binary, dst_fd, COPYFD_SPARSE);
fa19501
     close(src_fd_binary);
fa19501
@@ -701,9 +701,7 @@ int main(int argc, char** argv)
fa19501
 
fa19501
         if (setting_SaveBinaryImage)
fa19501
         {
fa19501
-            strcpy(path + path_len, "/"FILENAME_BINARY);
fa19501
-
fa19501
-            if (save_crashing_binary(pid, path, dd->dd_uid, dd->dd_gid))
fa19501
+            if (save_crashing_binary(pid, dd))
fa19501
             {
fa19501
                 error_msg("Error saving '%s'", path);
fa19501
 
fa19501
-- 
fa19501
2.1.0
fa19501