From 84eeef108d36c7aa725e6b8098960937c5d1b38e Mon Sep 17 00:00:00 2001
From: Scott Tsai <scottt.tw@gmail.com>
Date: Fri, 16 Dec 2011 05:56:39 +0800
Subject: [PATCH] svf: guard against chain->cable being NULL
While processing:
cable ft2232 vid=0x0403 pid=0x6011
bsdl path .
detect
svf ./orpsoc_top.svf stop progress
quit
If the specified cable isn't present, jtag would SEGFAULT with this backtrace:
#0 urj_tap_cable_get_frequency (cable=0x0) at cable.c:529
#1 0x00007fefd4f4803a in urj_svf_run (chain=0x20562a0, SVF_FILE=0x20567b0, stop_on_mismatch=1, ref_freq=0) at svf.c:1117
#2 0x00007fefd4f40681 in cmd_svf_run (chain=0x20562a0, params=0x20565a0) at cmd_svf.c:83
#3 0x00007fefd4f3e9ad in urj_cmd_run (chain=0x20562a0, params=0x20565a0) at cmd_cmd.c:276
#4 0x00007fefd4f4438d in urj_parse_line (chain=0x20562a0, line=0x2056520 "svf ./orpsoc_top.svf stop progress") at parse.c:165
#5 0x00007fefd4f44447 in urj_parse_stream (chain=0x20562a0, f=0x20562e0) at parse.c:207
#6 0x00007fefd4f4456b in urj_parse_file (chain=0x20562a0, filename=0x7fff90576b92 "./program_fpga.jtag") at parse.c:235
#7 0x00000000004016c1 in main (argc=2, argv=<optimized out>) at jtag.c:486
This patch changes urj_svf_run to guard against chain->cable being NULL.
---
urjtag/src/svf/svf.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/urjtag/src/svf/svf.c b/urjtag/src/svf/svf.c
index 9552a6d..2282c77 100644
--- a/urjtag/src/svf/svf.c
+++ b/urjtag/src/svf/svf.c
@@ -1114,7 +1114,12 @@ urj_svf_run (urj_chain_t *chain, FILE *SVF_FILE, int stop_on_mismatch,
urj_svf_parser_priv_t priv;
int c = ~EOF;
int num_lines;
- uint32_t old_frequency = urj_tap_cable_get_frequency (chain->cable);
+ uint32_t old_frequency;
+
+ if (chain == NULL || chain->cable == NULL)
+ return URJ_STATUS_FAIL;
+
+ old_frequency = urj_tap_cable_get_frequency (chain->cable);
/* get number of lines in svf file so we can give user some feedback on long
files or slow cables */
--
1.7.7.5