summaryrefslogtreecommitdiff
path: root/tools/thermal/tmon/tmon.c
diff options
context:
space:
mode:
authorFrank Asseg <frank.asseg@objecthunter.net>2018-03-12 21:57:06 +0300
committerJiri Kosina <jkosina@suse.cz>2018-03-27 10:51:23 +0300
commit6c59f64b7ecf2bccbe73931d7d573d66ed13b537 (patch)
tree3e0be7a9e2ccb0a8372ab0c3d9c7a1faf882d9a4 /tools/thermal/tmon/tmon.c
parentb903036aad6c46f0c94b3a58c86f7467776a5dcf (diff)
downloadlinux-6c59f64b7ecf2bccbe73931d7d573d66ed13b537.tar.xz
tools/thermal: tmon: fix for segfault
Fixes a segfault occurring when e.g. <TAB> is pressed multiple times in the ncurses tmon application. The segfault is caused by incrementing cur_thermal_record in the main function without checking if it's value reached NR_THERMAL_RECORD immediately. Since the boundary check only occurred in update_thermal_data a race condition existed, which lead to an attempted read beyond the last element of the trec array. The fix was implemented by moving the cur_thermal_record incrementation to the update_thermal_data function using a temporary variable on which the boundary condition is checked before updating cur_thread_record, so that the variable is never incremented beyond the trec array's boundary. It seems the segfault does not occur on every machine: On a HP EliteBook G4 the segfault happens, while it does not happen on a Thinkpad T540p. Signed-off-by: Frank Asseg <frank.asseg@objecthunter.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'tools/thermal/tmon/tmon.c')
-rw-r--r--tools/thermal/tmon/tmon.c1
1 files changed, 0 insertions, 1 deletions
diff --git a/tools/thermal/tmon/tmon.c b/tools/thermal/tmon/tmon.c
index 9aa19652e8e8..b43138f8b862 100644
--- a/tools/thermal/tmon/tmon.c
+++ b/tools/thermal/tmon/tmon.c
@@ -336,7 +336,6 @@ int main(int argc, char **argv)
show_data_w();
show_cooling_device();
}
- cur_thermal_record++;
time_elapsed += ticktime;
controller_handler(trec[0].temp[target_tz_index] / 1000,
&yk);