diff --git a/PKGBUILD b/PKGBUILD index 600ef26..773fa22 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -11,16 +11,31 @@ depends=('glibc') makedepends=('patch') backup=(etc/foremost.conf) source=(https://foremost.sourceforge.net/pkg/$pkgname-$pkgver.tar.gz - $pkgname-makefile.patch - $pkgname-1.5.7-fno-common.patch) + $pkgname-1.5.7-config-path.patch + $pkgname-1.5.7-Makefile.patch + $pkgname-1.5.7-fno-common.patch + $pkgname-1.5.7-format-security.patch + $pkgname-1.5.7-broken-jpeg.patch + $pkgname-1.5.7-enforce-limits.patch) sha512sums=('8827c29d52496783be26374f3943eb26a154d842f34e50fb489f87b3a5045bf85f1e44d7d8d8b12b2355ba3fe4b06a0db979cc22c0f431593c5976001eb931ab' - 'eb3fc70590cafa3fb953946f6d80051ab3d976bcb3687cadb141a72dbd5bf317de68f39db7e28e27b49dd1629cab7e4c0ff5bc83c962c33026e9fe4d4ad2dc96' - '4a129e0bb97f2c8aa09d6861077e732886e1d26573cc8698abfb03b55ebcf73c7ba1fbd6de25c5a4d2ce8cd271ebf07aa277d823d54640e6922ebc72a6aaba46') + '97b132d9cbd17463e3ede85e8c48cfaf1f6048c040f810e1f78c5f174251c673fe3bb0ef9c3f914a7983c3686426cbf89dd414e76c19982cf217a12a602e3b63' + '40f787ac82220aca45ff2f894cc69529526839c2db60094b2bc39067567313907e9bdeace1648e50a344d9c105598679a834cf411bae6494f8d60998b0c6218b' + '4a129e0bb97f2c8aa09d6861077e732886e1d26573cc8698abfb03b55ebcf73c7ba1fbd6de25c5a4d2ce8cd271ebf07aa277d823d54640e6922ebc72a6aaba46' + 'f9682baabcdbcf2c51ca7d9a41c95a10920123468c7bc207fb94708e0f652cf086659ae24e253abc02789d074b3a298f5d89e8ea3aff0328d92c0931500d9d61' + '78e4336a05990036f0346f200880bca9d920ae2e01121e51e98157365413590f76cfd03e9b4a5ebc34cd4f58367d9e02b32af6c732a932eff54f9a21d1b8edba' + '031494376d8e1ed340892540ba64024a4e45f3d66e8b929db4d869b2045e367580a98669b66c099a83820187d67aeb681a31de2d653cb501a1c1e594ca23bf5e') prepare() { cd "${srcdir}"/$pkgname-$pkgver - patch -Np0 -i "${srcdir}"/$pkgname-makefile.patch - patch -Np1 -i "${srcdir}"/$pkgname-1.5.7-fno-common.patch + local src + for src in "${source[@]}"; do + src="${src%%::*}" + src="${src##*/}" + [[ $src = *.patch ]] || continue + echo "Applying patch $src..." + patch -Np1 < "../$src" + done + } build() { diff --git a/foremost-1.5.7-Makefile.patch b/foremost-1.5.7-Makefile.patch new file mode 100644 index 0000000..9f6eaa0 --- /dev/null +++ b/foremost-1.5.7-Makefile.patch @@ -0,0 +1,49 @@ +diff --git a/Makefile b/Makefile +index 1a20f4f..0482ecf 100755 +--- a/Makefile ++++ b/Makefile +@@ -1,7 +1,3 @@ +- +-RAW_CC = gcc +-RAW_FLAGS = -Wall -O2 +-LINK_OPT = + VERSION = 1.5.7 + # Try to determine the host system + SYS := $(shell uname -s | tr -d "[0-9]" | tr -d "-" | tr "[A-Z]" "[a-z]") +@@ -21,12 +17,12 @@ CR_BASE = /usr/local/cross-tools/i386-mingw32msvc/bin + NAME = foremost + MAN_PAGES = $(NAME).8.gz + +-RAW_FLAGS += -DVERSION=\"$(VERSION)\" ++CFLAGS += -DVERSION=\"$(VERSION)\" + + # Where we get installed +-BIN = /usr/local/bin +-MAN = /usr/share/man/man8 +-CONF= /usr/local/etc ++BIN = $(DESTDIR)/usr/bin ++MAN = $(DESTDIR)/usr/share/man/man8 ++CONF = $(DESTDIR)/etc + # Setup for compiling and cross-compiling for Windows + # The CR_ prefix refers to cross compiling from OSX to Windows + CR_CC = $(CR_BASE)/gcc +@@ -37,9 +33,7 @@ CR_GOAL = $(NAME).exe + WINCC = $(RAW_CC) $(RAW_FLAGS) -D__WIN32 + + # Generic "how to compile C files" +-CC = $(RAW_CC) $(RAW_FLAGS) -D__UNIX +-.c.o: +- $(CC) -c $< ++CFLAGS += -D__UNIX + + + # Definitions we'll need later (and that should rarely change) +@@ -110,7 +104,7 @@ cygwin: unix + #--------------------------------------------------------------------- + + foremost: $(OBJ) +- $(CC) $(OBJ) -o $(NAME) $(LINK_OPT) ++ $(CC) $(OBJ) -o $(NAME) $(LDFLAGS) + + + #--------------------------------------------------------------------- diff --git a/foremost-1.5.7-broken-jpeg.patch b/foremost-1.5.7-broken-jpeg.patch new file mode 100644 index 0000000..97a8a9e --- /dev/null +++ b/foremost-1.5.7-broken-jpeg.patch @@ -0,0 +1,18 @@ +diff --git a/extract.c b/extract.c +index 7c2a259..1d015d0 100755 +--- a/extract.c ++++ b/extract.c +@@ -1869,7 +1869,12 @@ unsigned char *extract_jpeg(f_state *s, u_int64_t c_offset, unsigned char *found + if (((foundat + headersize) - buf) > buflen){ return NULL; } + + foundat += headersize; +- ++ ++ if (foundat >= (buf + buflen)) ++ { ++ return buf + needle->header_len; ++ } ++ + if (foundat[2] != (unsigned char)'\xff') + { + break; diff --git a/foremost-1.5.7-config-path.patch b/foremost-1.5.7-config-path.patch new file mode 100644 index 0000000..317d8b7 --- /dev/null +++ b/foremost-1.5.7-config-path.patch @@ -0,0 +1,16 @@ +Description: Look in /etc for config file by default +Origin: vendor +Forwarded: no +Author: Gürkan Sengün +Last-update: 2012-05-13 +--- a/config.c ++++ b/config.c +@@ -288,7 +288,7 @@ + #ifdef __WIN32 + set_config_file(s, "/Program Files/foremost/foremost.conf"); + #else +- set_config_file(s, "/usr/local/etc/foremost.conf"); ++ set_config_file(s, "/etc/foremost.conf"); + #endif + if ((f = fopen(get_config_file(s), "r")) == NULL) + { diff --git a/foremost-1.5.7-enforce-limits.patch b/foremost-1.5.7-enforce-limits.patch new file mode 100644 index 0000000..1685327 --- /dev/null +++ b/foremost-1.5.7-enforce-limits.patch @@ -0,0 +1,72 @@ +Author: Raúl Benencia +Description: Enforce limits + Enforce limits on the amount of possible patterns and the length of the config + lines in order to avoid segmentation faults and undefined behaviour. +diff --git a/config.c b/config.c +index 89fd377..c6dae3b 100755 +--- a/config.c ++++ b/config.c +@@ -187,6 +187,15 @@ int process_line(f_state *s, char *buffer, int line_number) + char **tokenarray = (char **)malloc(6 * sizeof(char[MAX_STRING_LENGTH])); + int i = 0, len = strlen(buffer); + ++ if (len == MAX_STRING_LENGTH - 1) ++ { ++ if (!(buffer[len -1] == '\n') || !(buffer[len - 2] == 0x0d && buffer[len - 1] == 0x0a)) ++ { ++ fprintf(stderr, "\nERROR: Foremost does not support lines longer than %d. Check line %d.\n", MAX_STRING_LENGTH, line_number); ++ return FALSE; ++ } ++ } ++ + /* Any line that ends with a CTRL-M (0x0d) has been processed + by a DOS editor. We will chop the CTRL-M to ignore it */ + if (buffer[len - 2] == 0x0d && buffer[len - 1] == 0x0a) +@@ -258,6 +267,12 @@ int process_line(f_state *s, char *buffer, int line_number) + + } + ++ if (s->num_builtin >= MAX_BUILTIN) ++ { ++ fprintf(stderr, "\nERROR: Reached maximum amount of entries. Line: %d. Maximum: %d\n", line_number, MAX_BUILTIN); ++ return FALSE; ++ } ++ + if (!extractSearchSpecData(s, tokenarray)) + { + fprintf(stderr, +diff --git a/main.c b/main.c +index df22350..fff5b7f 100755 +--- a/main.c ++++ b/main.c +@@ -244,7 +244,8 @@ int main(int argc, char **argv) + register_signal_handler(); + process_command_line(argc, argv, s); + +- load_config_file(s); ++ if (load_config_file(s)) ++ fatal_error(s, "Unable to load the config file"); + + if (s->num_builtin == 0) + { +diff --git a/main.h b/main.h +index 879686e..5486bb6 100755 +--- a/main.h ++++ b/main.h +@@ -198,6 +198,7 @@ char *__progname; + Program Defaults + ----------------------------------------------------------------- */ + #define MAX_STRING_LENGTH 1024 ++#define MAX_BUILTIN 50 + #define COMMENT_LENGTH 64 + + /* Modes refer to options that can be set by the user. */ +@@ -344,7 +345,7 @@ typedef struct s_spec + int written; /*used for -a mode*/ + }s_spec; + +-extern s_spec search_spec[50]; /*ARRAY OF BUILTIN SEARCH TYPES*/ ++extern s_spec search_spec[MAX_BUILTIN]; /*ARRAY OF BUILTIN SEARCH TYPES*/ + + typedef struct f_info { + char *file_name; diff --git a/foremost-1.5.7-format-security.patch b/foremost-1.5.7-format-security.patch new file mode 100644 index 0000000..eb9a60c --- /dev/null +++ b/foremost-1.5.7-format-security.patch @@ -0,0 +1,22 @@ +diff --git a/extract.c b/extract.c +index 3ef98a0..7c2a259 100755 +--- a/extract.c ++++ b/extract.c +@@ -2111,7 +2111,6 @@ unsigned char *extract_exe(f_state *s, u_int64_t c_offset, unsigned char *founda + int i = 0; + time_t compile_time = 0; + struct tm *ret_time; +- char comment[32]; + char ascii_time[32]; + + if (buflen < 100) +@@ -2146,8 +2145,7 @@ unsigned char *extract_exe(f_state *s, u_int64_t c_offset, unsigned char *founda + ret_time->tm_sec); + chop(ascii_time); + +- sprintf(comment, ascii_time); +- strcat(needle->comment, comment); ++ strcat(needle->comment, ascii_time); + exe_char = htos(&foundat[22], FOREMOST_LITTLE_ENDIAN); + if (exe_char & 0x2000) + { diff --git a/foremost-makefile.patch b/foremost-makefile.patch deleted file mode 100644 index dc3683e..0000000 --- a/foremost-makefile.patch +++ /dev/null @@ -1,23 +0,0 @@ ---- Makefile.orig 2008-10-14 02:09:13.000000000 +0200 -+++ Makefile 2008-10-14 18:31:38.000000000 +0200 -@@ -26,5 +26,5 @@ - # Where we get installed --BIN = /usr/local/bin --MAN = /usr/share/man/man8 --CONF= /usr/local/etc -+BIN = $(DESTDIR)/usr/bin -+MAN = $(DESTDIR)/usr/share/man/man8 -+CONF= $(DESTDIR)/etc - # Setup for compiling and cross-compiling for Windows -diff -uNr foremost-1.4.orig/config.c foremost-1.4/config.c ---- config.c 2006-08-31 17:50:47.000000000 +0100 -+++ config.c 2006-08-31 17:51:09.000000000 +0100 -@@ -288,7 +288,7 @@ - #ifdef __WIN32 - set_config_file(s, "/Program Files/foremost/foremost.conf"); - #else -- set_config_file(s, "/usr/local/etc/foremost.conf"); -+ set_config_file(s, "/etc/foremost.conf"); - #endif - if ((f = fopen(get_config_file(s), "r")) == NULL) - {