Prevent buffer overflow in realpath

This patch prevents a buffer overflow in the
realpath function.

Thanks to Abel Abraham Camarillo Ojeda
This commit is contained in:
Moritz Lipp 2010-06-06 19:27:10 +02:00
parent 62937222af
commit f3e57c633d

View File

@ -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] == '~')
{