From 33fb2bed58e9f4dfadd2f69f90e474fd46099419 Mon Sep 17 00:00:00 2001 From: "Kelvin M. Klann" Date: Fri, 16 Jun 2023 16:02:43 -0300 Subject: Deduplicate calls similar to errExit Use errExit in every place that uses __FILE__ and __LINE__ manually. Note: This currently only happens in the duplicated `is_dir` function. --- src/fbuilder/utils.c | 4 +--- src/firejail/util.c | 4 +--- src/ftee/main.c | 6 ++---- 3 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/fbuilder/utils.c b/src/fbuilder/utils.c index fa432d003..91c5a1a5e 100644 --- a/src/fbuilder/utils.c +++ b/src/fbuilder/utils.c @@ -34,10 +34,8 @@ int is_dir(const char *fname) { rv = stat(fname, &s); else { char *tmp; - if (asprintf(&tmp, "%s/", fname) == -1) { - fprintf(stderr, "Error: cannot allocate memory, %s:%d\n", __FILE__, __LINE__); + if (asprintf(&tmp, "%s/", fname) == -1) errExit("asprintf"); - } rv = stat(tmp, &s); free(tmp); } diff --git a/src/firejail/util.c b/src/firejail/util.c index 555486916..87b771867 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c @@ -559,10 +559,8 @@ int is_dir(const char *fname) { rv = stat_as_user(fname, &s); else { char *tmp; - if (asprintf(&tmp, "%s/", fname) == -1) { - fprintf(stderr, "Error: cannot allocate memory, %s:%d\n", __FILE__, __LINE__); + if (asprintf(&tmp, "%s/", fname) == -1) errExit("asprintf"); - } rv = stat_as_user(tmp, &s); free(tmp); } diff --git a/src/ftee/main.c b/src/ftee/main.c index a34a76b26..20e25c202 100644 --- a/src/ftee/main.c +++ b/src/ftee/main.c @@ -148,10 +148,8 @@ static int is_dir(const char *fname) { rv = stat(fname, &s); else { char *tmp; - if (asprintf(&tmp, "%s/", fname) == -1) { - fprintf(stderr, "Error: cannot allocate memory, %s:%d\n", __FILE__, __LINE__); - exit(1); - } + if (asprintf(&tmp, "%s/", fname) == -1) + errExit("asprintf"); rv = stat(tmp, &s); free(tmp); } -- cgit v1.2.3-54-g00ecf From 1989a0f46ad11a235d6788f7fbed880cd02aad19 Mon Sep 17 00:00:00 2001 From: "Kelvin M. Klann" Date: Fri, 16 Jun 2023 15:38:22 -0300 Subject: common.h: line-wrap errExit --- src/include/common.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/include/common.h b/src/include/common.h index a0ad8c765..060945f82 100644 --- a/src/include/common.h +++ b/src/include/common.h @@ -35,8 +35,12 @@ // dbus proxy path used by firejail and firemon #define XDG_DBUS_PROXY_PATH "/usr/bin/xdg-dbus-proxy" - -#define errExit(msg) do { char msgout[500]; snprintf(msgout, 500, "Error %s: %s:%d %s", msg, __FILE__, __LINE__, __FUNCTION__); perror(msgout); exit(1);} while (0) +#define errExit(msg) do { \ + char msgout[500]; \ + snprintf(msgout, 500, "Error %s: %s:%d %s", msg, __FILE__, __LINE__, __FUNCTION__); \ + perror(msgout); \ + exit(1); \ +} while (0) // macro to print ip addresses in a printf statement #define PRINT_IP(A) \ -- cgit v1.2.3-54-g00ecf From e06c3e99d8d42d3422bf8ebf50fd500da1cf4ccf Mon Sep 17 00:00:00 2001 From: "Kelvin M. Klann" Date: Sat, 17 Jun 2023 15:09:35 -0300 Subject: common.h: use __func__ instead of __FUNCTION__ For increased portability. The former is in C99, the latter is from gcc. --- src/include/common.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/include/common.h b/src/include/common.h index 060945f82..23b00b6f8 100644 --- a/src/include/common.h +++ b/src/include/common.h @@ -32,12 +32,16 @@ #include #include +#if !defined(__func__) && defined(__FUNCTION__) +#define __func__ __FUNCTION__ +#endif + // dbus proxy path used by firejail and firemon #define XDG_DBUS_PROXY_PATH "/usr/bin/xdg-dbus-proxy" #define errExit(msg) do { \ char msgout[500]; \ - snprintf(msgout, 500, "Error %s: %s:%d %s", msg, __FILE__, __LINE__, __FUNCTION__); \ + snprintf(msgout, 500, "Error %s: %s:%d %s", msg, __FILE__, __LINE__, __func__); \ perror(msgout); \ exit(1); \ } while (0) -- cgit v1.2.3-54-g00ecf From b963fe41ae2cd669e5819aded531375ddaebc8b2 Mon Sep 17 00:00:00 2001 From: "Kelvin M. Klann" Date: Fri, 16 Jun 2023 15:42:20 -0300 Subject: Improve errExit error messages Changes: * Move msg to the end of errExit (right before perror(3p)) * Include the full file path (within the repository) * Add "()" to function name for clarity Before: Error malloc: main.c:123 main: Cannot allocate memory After: Error src/firejail/main.c:123 main(): malloc: Cannot allocate memory Note: This clarifies which is the exact file that the error message comes from, as there are many source files with the same name. For example: $ git ls-files 'src/*/main.c' | wc -l 20 --- config.mk.in | 2 +- src/etc-cleanup/Makefile | 1 + src/fbuilder/Makefile | 1 + src/fcopy/Makefile | 1 + src/fids/Makefile | 1 + src/firecfg/Makefile | 1 + src/firejail/Makefile | 1 + src/firemon/Makefile | 1 + src/fldd/Makefile | 1 + src/fnet/Makefile | 1 + src/fnetfilter/Makefile | 1 + src/fnettrace-dns/Makefile | 1 + src/fnettrace-icmp/Makefile | 1 + src/fnettrace-sni/Makefile | 1 + src/fnettrace/Makefile | 1 + src/fsec-optimize/Makefile | 1 + src/fsec-print/Makefile | 1 + src/fseccomp/Makefile | 1 + src/ftee/Makefile | 1 + src/fzenity/Makefile | 1 + src/include/common.h | 3 ++- src/jailcheck/Makefile | 1 + src/lib/Makefile | 1 + src/libpostexecseccomp/Makefile | 1 + src/libtrace/Makefile | 1 + src/libtracelog/Makefile | 1 + src/profstats/Makefile | 1 + test/appimage/filename.exp | 2 +- 28 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/config.mk.in b/config.mk.in index f3c1f658c..c76ca1a98 100644 --- a/config.mk.in +++ b/config.mk.in @@ -83,7 +83,7 @@ LDFLAGS=@LDFLAGS@ # Project variables EXTRA_CFLAGS =@EXTRA_CFLAGS@ COMMON_CFLAGS = \ - -ggdb -O2 -DVERSION='"$(VERSION)"' \ + -ggdb -O2 -DVERSION='"$(VERSION)"' -DMOD_DIR='"$(MOD_DIR)"' \ -Wall -Wextra $(HAVE_FATAL_WARNINGS) \ -Wformat -Wformat-security \ -fstack-protector-all -D_FORTIFY_SOURCE=2 \ diff --git a/src/etc-cleanup/Makefile b/src/etc-cleanup/Makefile index c3c482bdb..296ed41d8 100644 --- a/src/etc-cleanup/Makefile +++ b/src/etc-cleanup/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/etc-cleanup PROG = etc-cleanup TARGET = $(PROG) diff --git a/src/fbuilder/Makefile b/src/fbuilder/Makefile index 634bf725f..1f6a28780 100644 --- a/src/fbuilder/Makefile +++ b/src/fbuilder/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fbuilder PROG = fbuilder TARGET = $(PROG) diff --git a/src/fcopy/Makefile b/src/fcopy/Makefile index a3c4abe9d..f82d3a073 100644 --- a/src/fcopy/Makefile +++ b/src/fcopy/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fcopy PROG = fcopy TARGET = $(PROG) diff --git a/src/fids/Makefile b/src/fids/Makefile index 76388a03d..c03740e3d 100644 --- a/src/fids/Makefile +++ b/src/fids/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fids PROG = fids TARGET = $(PROG) diff --git a/src/firecfg/Makefile b/src/firecfg/Makefile index de4639ab6..322ce3e3f 100644 --- a/src/firecfg/Makefile +++ b/src/firecfg/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/firecfg PROG = firecfg TARGET = $(PROG) diff --git a/src/firejail/Makefile b/src/firejail/Makefile index d3a4b4f81..a817b1757 100644 --- a/src/firejail/Makefile +++ b/src/firejail/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/firejail PROG = firejail TARGET = $(PROG) diff --git a/src/firemon/Makefile b/src/firemon/Makefile index 09387f3eb..649bad0af 100644 --- a/src/firemon/Makefile +++ b/src/firemon/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/firemon PROG = firemon TARGET = $(PROG) diff --git a/src/fldd/Makefile b/src/fldd/Makefile index 7fec70a33..00173d18e 100644 --- a/src/fldd/Makefile +++ b/src/fldd/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fldd PROG = fldd TARGET = $(PROG) diff --git a/src/fnet/Makefile b/src/fnet/Makefile index 50bfdfffd..04a200951 100644 --- a/src/fnet/Makefile +++ b/src/fnet/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fnet PROG = fnet TARGET = $(PROG) diff --git a/src/fnetfilter/Makefile b/src/fnetfilter/Makefile index 156af3ed0..d38185fb1 100644 --- a/src/fnetfilter/Makefile +++ b/src/fnetfilter/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fnetfilter PROG = fnetfilter TARGET = $(PROG) diff --git a/src/fnettrace-dns/Makefile b/src/fnettrace-dns/Makefile index bbd4772e2..fb1054261 100644 --- a/src/fnettrace-dns/Makefile +++ b/src/fnettrace-dns/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fnettrace-dns PROG = fnettrace-dns TARGET = $(PROG) diff --git a/src/fnettrace-icmp/Makefile b/src/fnettrace-icmp/Makefile index 0d26dc2fc..4791e0b9f 100644 --- a/src/fnettrace-icmp/Makefile +++ b/src/fnettrace-icmp/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fnettrace-icmp PROG = fnettrace-icmp TARGET = $(PROG) diff --git a/src/fnettrace-sni/Makefile b/src/fnettrace-sni/Makefile index 554741fc8..09a444db0 100644 --- a/src/fnettrace-sni/Makefile +++ b/src/fnettrace-sni/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fnettrace-sni PROG = fnettrace-sni TARGET = $(PROG) diff --git a/src/fnettrace/Makefile b/src/fnettrace/Makefile index 94381d299..fe74afda2 100644 --- a/src/fnettrace/Makefile +++ b/src/fnettrace/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fnettrace PROG = fnettrace TARGET = $(PROG) diff --git a/src/fsec-optimize/Makefile b/src/fsec-optimize/Makefile index 5a14726a0..12ac5f1a9 100644 --- a/src/fsec-optimize/Makefile +++ b/src/fsec-optimize/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fsec-optimize PROG = fsec-optimize TARGET = $(PROG) diff --git a/src/fsec-print/Makefile b/src/fsec-print/Makefile index d55167796..a506c1106 100644 --- a/src/fsec-print/Makefile +++ b/src/fsec-print/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fsec-print PROG = fsec-print TARGET = $(PROG) diff --git a/src/fseccomp/Makefile b/src/fseccomp/Makefile index f8c35d41f..a7d88eb83 100644 --- a/src/fseccomp/Makefile +++ b/src/fseccomp/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fseccomp PROG = fseccomp TARGET = $(PROG) diff --git a/src/ftee/Makefile b/src/ftee/Makefile index 0c27b4cbc..1b1cdec43 100644 --- a/src/ftee/Makefile +++ b/src/ftee/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/ftee PROG = ftee TARGET = $(PROG) diff --git a/src/fzenity/Makefile b/src/fzenity/Makefile index 148babbe8..cb80ec0bc 100644 --- a/src/fzenity/Makefile +++ b/src/fzenity/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/fzenity PROG = fzenity TARGET = $(PROG) diff --git a/src/include/common.h b/src/include/common.h index 23b00b6f8..4a2b8c1bf 100644 --- a/src/include/common.h +++ b/src/include/common.h @@ -41,7 +41,8 @@ #define errExit(msg) do { \ char msgout[500]; \ - snprintf(msgout, 500, "Error %s: %s:%d %s", msg, __FILE__, __LINE__, __func__); \ + snprintf(msgout, 500, "Error %s/%s:%d %s(): %s", \ + MOD_DIR, __FILE__, __LINE__, __func__, msg); \ perror(msgout); \ exit(1); \ } while (0) diff --git a/src/jailcheck/Makefile b/src/jailcheck/Makefile index 3b0b83412..0b57861c6 100644 --- a/src/jailcheck/Makefile +++ b/src/jailcheck/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/jailcheck PROG = jailcheck TARGET = $(PROG) diff --git a/src/lib/Makefile b/src/lib/Makefile index a7b093048..9cf8abe36 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/lib TARGET = lib include $(ROOT)/src/prog.mk diff --git a/src/libpostexecseccomp/Makefile b/src/libpostexecseccomp/Makefile index c5ec14672..c9e25d066 100644 --- a/src/libpostexecseccomp/Makefile +++ b/src/libpostexecseccomp/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/libpostexecseccomp SO = libpostexecseccomp.so TARGET = $(SO) diff --git a/src/libtrace/Makefile b/src/libtrace/Makefile index 8b14a4335..337529361 100644 --- a/src/libtrace/Makefile +++ b/src/libtrace/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/libtrace SO = libtrace.so TARGET = $(SO) diff --git a/src/libtracelog/Makefile b/src/libtracelog/Makefile index 2b43ce131..3e9d9e3e3 100644 --- a/src/libtracelog/Makefile +++ b/src/libtracelog/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/libtracelog SO = libtracelog.so TARGET = $(SO) diff --git a/src/profstats/Makefile b/src/profstats/Makefile index ae88bf2fd..aa947401e 100644 --- a/src/profstats/Makefile +++ b/src/profstats/Makefile @@ -2,6 +2,7 @@ ROOT = ../.. -include $(ROOT)/config.mk +MOD_DIR = src/profstats PROG = profstats TARGET = $(PROG) diff --git a/test/appimage/filename.exp b/test/appimage/filename.exp index 9d9127fb5..f2b827bb6 100755 --- a/test/appimage/filename.exp +++ b/test/appimage/filename.exp @@ -24,7 +24,7 @@ after 100 send -- "firejail --appimage appimage.sh\r" expect { timeout {puts "TESTING ERROR 2\n";exit} - "Error mounting appimage" + -re "Error .*mounting appimage" } after 100 -- cgit v1.2.3-54-g00ecf