mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-22 22:28:02 +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:
committed by
Carlos R. Mafra
parent
34f35ee534
commit
33855a7a12
@@ -26,6 +26,8 @@
|
||||
#include <X11/XKBlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
@@ -641,6 +643,12 @@ static void storeCommandInScript(const char *cmd, const char *line)
|
||||
char *path;
|
||||
FILE *f;
|
||||
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");
|
||||
|
||||
@@ -700,9 +708,8 @@ static void storeCommandInScript(const char *cmd, const char *line)
|
||||
}
|
||||
wfree(tmppath);
|
||||
}
|
||||
sprintf(buffer, "chmod u+x %s", path);
|
||||
if (system(buffer) == -1)
|
||||
werror(_("could not execute command \"%s\""), buffer);
|
||||
if (chmod(path, permissions) != 0)
|
||||
wwarning(_("could not set permission 0%03o on file \"%s\""), permissions, path);
|
||||
|
||||
end:
|
||||
wfree(path);
|
||||
|
||||
Reference in New Issue
Block a user