From 6d3bce6920712d98ac0ed3a295df7f19ed815362 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Jun 2010 19:27:10 +0200 Subject: [PATCH] Prevent buffer overflow in realpath This patch prevents a buffer overflow in the realpath function. Thanks to Abel Abraham Camarillo Ojeda --- zathura.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/zathura.c b/zathura.c index 1e78443..faa8158 100644 --- a/zathura.c +++ b/zathura.c @@ -898,8 +898,24 @@ open_file(char* path, char* password) { g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); + /* specify path max */ + size_t pm; +#ifdef PATH_MAX + pm = PATH_MAX; +#else + pm = pathconf(path,_PC_PATH_MAX); + if(pm <= 0) + pm = 4096; +#endif + /* get filename */ - char* file = realpath(path, NULL); + char* file = (char*) calloc(sizeof(char), pm); + if(!file || !realpath(path, file)) + { + if(file) + free(file); + return FALSE; + } if(path[0] == '~') {