1
0
mirror of https://github.com/rd235/cado synced 2024-12-26 14:03:07 +01:00

ignore retvalue (credit @rd235)

This commit is contained in:
Mattia Biondi 2020-01-09 19:50:58 +01:00
parent d9082075ba
commit 97a13ad95b
4 changed files with 20 additions and 13 deletions

View File

@ -6,7 +6,7 @@ project(cado
LANGUAGES C)
include(GNUInstallDirs)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2 -O2 -Wall -pedantic")
set(LIBS_REQUIRED cap execs mhash pam pam_misc)

View File

@ -198,7 +198,10 @@ int main(int argc, char*argv[])
grantcap = reqcaps & okcaps;
/* revert setgid mode */
setuid(getuid());
if (setuid(getuid()) < 0) {
fprintf(stderr,"%s: setuid failure\n",progname);
exit(2);
}
/* ask for pam authorization (usually password) if required */
if (pam_check_required && pam_check(user_groups[0]) != PAM_SUCCESS) {

View File

@ -43,7 +43,12 @@ static ssize_t fcompute_digest(int infd, int outfd, char *ascii_digest) {
while ((n=read(infd,buf,BUFSIZE)) > 0) {
mhash(td, buf, n);
if (outfd >= 0) write(outfd, buf, n);
if (outfd >= 0) {
if (write(outfd, buf, n) < 0) {
n = -1;
break;
}
}
rv += n;
}

View File

@ -97,12 +97,12 @@ static int editor_garbage_collect(char *path) {
if(!(childpid = fork())) {
/* Child */
if(!fork()) {
char c = 0;
/* Grandchild */
if (close(checkpipe[1]) == 0 && setsid() > 0)
read(checkpipe[0], &c, 1);
if (c == 0)
unlink(path);
if (close(checkpipe[1]) == 0 && setsid() > 0) {
char c;
if (read(checkpipe[0], &c, 1) == 0)
unlink(path);
}
exit(0);
} else
exit(0);
@ -115,7 +115,8 @@ static int editor_garbage_collect(char *path) {
static void editor_garbage_collect_do_not_unlink(int fd) {
char c = 'K'; // keep it, any other non-null char would fit.
write(fd, &c, 1);
int n = write(fd, &c, 1);
(void) n;
}
/* command line selectable functions */
@ -188,7 +189,7 @@ int scado_edit(char *progname, char *username, char *program_path) {
char tmp_file[PATH_MAX];
char scado_file[PATH_MAX];
char *editor;
char *args = NULL;
char *args;
int status = 0;
pid_t pid, xpid;
char digest_before[DIGESTSTRLEN + 1];
@ -242,9 +243,7 @@ int scado_edit(char *progname, char *username, char *program_path) {
exit(ERROR_EXIT);
}
asprintf(&args, "%s %s", editor, tmp_file);
if (args == NULL) {
if (asprintf(&args, "%s %s", editor, tmp_file) < 0) {
exit(ERROR_EXIT);
}