1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
From: Thomas Loimer <thomas.loimer@tuwien.ac.at>
Date: Fri, 31 Dec 2021 23:27:18 +0100
Origin: upstream, https://sourceforge.net/p/mcj/xfig/ci/ecbf488
Subject: Fix a heap-use-after-free
When compiled with -fsanitize=address, xfig would crash if there were two more
recent fig files than max_recent_files. For instance, if
.xfigrc contained
file: /tmp/a.fig
file: /tmp/b.fig
file: /tmp/c.fig
file: /tmp/d.fig
file: /tmp/e.fig
max_recent_files: 3
then, xfig /tmp/b.fig would access de-allocated memory. This commit fixes this
issue.
--- a/src/f_load.c
+++ b/src/f_load.c
@@ -1,8 +1,9 @@
/*
* FIG : Facility for Interactive Generation of figures
* Copyright (c) 1985-1988 by Supoj Sutanthavibul
- * Parts Copyright (c) 1989-2007 by Brian V. Smith
+ * Parts Copyright (c) 1989-2015 by Brian V. Smith
* Parts Copyright (c) 1991 by Paul King
+ * Parts Copyright (c) 2016-2021 by Thomas Loimer
*
* Any party obtaining a copy of these files is granted, free of charge, a
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
@@ -327,8 +328,9 @@ update_recent_list(char *file)
/* first, push older entries down one slot */
for (i=num_recent_files; i>0; i--) {
if (i >= max_recent_files) {
- /* pushing one off the end, free it's name */
+ /* pushing superfluous off the end, free their name */
free(recent_files[i-1].name);
+ num_recent_files = max_recent_files;
continue;
}
/* shift down */
@@ -340,7 +342,7 @@ update_recent_list(char *file)
/* put new entry in first slot */
/* prepend with file number (1) */
- name = new_string(strlen(file)+4);
+ name = new_string(strlen(file)+3);
sprintf(name,"1 %s",file);
recent_files[0].name = name;
if (num_recent_files < max_recent_files)
|