1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 14:08:06 +01:00

WPrefs: replaced call to external program "chmod" by the equivalent system call

It is more efficient to use the dedicated function than to call an external
binary program to do the job, and it reduce the risk of problem in case the
path would end up with potentially problematic characters.

It should also close Coverity bug #50225 ("Use of untrusted string value")

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-11-08 20:49:40 +01:00
committed by Carlos R. Mafra
parent 34f35ee534
commit 33855a7a12

View File

@@ -26,6 +26,8 @@
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h> #include <math.h>
@@ -641,6 +643,12 @@ static void storeCommandInScript(const char *cmd, const char *line)
char *path; char *path;
FILE *f; FILE *f;
char buffer[128]; char buffer[128];
mode_t permissions;
/* Calculate permission to be Executable but taking into account user's umask */
permissions = umask(0);
umask(permissions);
permissions = (S_IRWXU | S_IRWXG | S_IRWXO) & (~permissions);
path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart"); path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart");
@@ -700,9 +708,8 @@ static void storeCommandInScript(const char *cmd, const char *line)
} }
wfree(tmppath); wfree(tmppath);
} }
sprintf(buffer, "chmod u+x %s", path); if (chmod(path, permissions) != 0)
if (system(buffer) == -1) wwarning(_("could not set permission 0%03o on file \"%s\""), permissions, path);
werror(_("could not execute command \"%s\""), buffer);
end: end:
wfree(path); wfree(path);