CVE-2013-4476: lib-util: split out file_save_mode() from file_save()
authorBjörn Baumbach <bb@sernet.de>
Tue, 29 Oct 2013 16:48:11 +0000 (17:48 +0100)
committerKarolin Seeger <kseeger@samba.org>
Mon, 11 Nov 2013 10:14:36 +0000 (11:14 +0100)
file_save_mode() writes files with specified mode.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=10234

Signed-off-by: Björn Baumbach <bb@sernet.de>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/util/samba_util.h
lib/util/util_file.c

index f98cf6066a3cb3aee077b0c1361d0f613e200e7a..243ed3e50da3ef334874402c448306a9df9f0e6c 100644 (file)
@@ -580,6 +580,8 @@ a line
 **/
 _PUBLIC_ void file_lines_slashcont(char **lines);
 
+_PUBLIC_ bool file_save_mode(const char *fname, const void *packet,
+                            size_t length, mode_t mode);
 /**
   save a lump of data into a file. Mostly used for debugging 
 */
index e031fc511225563869a93aa537f65550e731dc6a..815cc2bf9e6cda7964cb0ef9f28fa6a29b1d4804 100644 (file)
@@ -368,13 +368,11 @@ _PUBLIC_ void file_lines_slashcont(char **lines)
        }
 }
 
-/**
-  save a lump of data into a file. Mostly used for debugging 
-*/
-_PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length)
+_PUBLIC_ bool file_save_mode(const char *fname, const void *packet,
+                            size_t length, mode_t mode)
 {
        int fd;
-       fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+       fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, mode);
        if (fd == -1) {
                return false;
        }
@@ -386,6 +384,14 @@ _PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length)
        return true;
 }
 
+/**
+  save a lump of data into a file. Mostly used for debugging
+*/
+_PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length)
+{
+       return file_save_mode(fname, packet, length, 0644);
+}
+
 _PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap)
 {
        char *p;