Ticket #5186: programs_mythfilldatabase_filldata.cpp-always-umask-before-mkstemp.patch

File programs_mythfilldatabase_filldata.cpp-always-umask-before-mkstemp.patch, 1.1 KB (added by Erik Hovland <erik@…>, 16 years ago)

wrap mkstemp() in umask() calls to make sure file perms are safe

  • programs/mythfilldatabase/filldata.cpp

    mkstemp is the right function to use to make temporary files. But always call umask
    
    From: Erik Hovland <erik@hovland.org>
    
    before calling it to make sure that no strange permissions get applied to the file.
    ---
    
     programs/mythfilldatabase/filldata.cpp |    7 ++++++-
     1 files changed, 6 insertions(+), 1 deletions(-)
    
    diff --git a/programs/mythfilldatabase/filldata.cpp b/programs/mythfilldatabase/filldata.cpp
    index 3904a12..964ac6e 100644
    a b  
    11// POSIX headers
    22#include <unistd.h>
    33#include <signal.h>
     4#include <sys/types.h>
     5#include <sys/stat.h>
    46
    57// Std C headers
    68#include <cstdlib>
    bool FillData::grabData(Source source, int offset, QDate *qCurrentDate) 
    306308    if (GetTempFileNameA("%TEMP%", "mth", 0, tempfilename) == 0)
    307309#else
    308310    char tempfilename[] = "/tmp/mythXXXXXX";
    309     if (mkstemp(tempfilename) == -1)
     311    mode_t cur_umask = umask(S_IRWXO | S_IRWXG);
     312    int ret = mkstemp(tempfilename);
     313    umask(cur_umask);
     314    if (ret == -1)
    310315#endif
    311316    {
    312317        VERBOSE(VB_IMPORTANT,