From 48c365e31c665c554503ec51b4662b33f6eabbec Mon Sep 17 00:00:00 2001
From: joerg_wunsch <joerg_wunsch@81a1dc3b-b13d-400b-aceb-764788c761c2>
Date: Sun, 23 Nov 2014 20:46:53 +0000
Subject: [PATCH] bug #43078: AVRDUDE crashes after sucessfully reading/writing
 eeprom * jtag3.c (jtag3_edbg_recv_frame): Return correct length as reported
 in the response packet, rather than full 512 byte which are always reported
 by the CMSIS-DAP layer.  Miscalculations based on the wrongly reported length
 caused heap corruption elsewhere, so this is presumably also a fix for bug
 #43078.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1344 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog | 9 +++++++++
 NEWS      | 1 +
 jtag3.c   | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index fccde052..9926bd31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2014-11-23  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
+
+	bug #43078: AVRDUDE crashes after sucessfully reading/writing eeprom
+	* jtag3.c (jtag3_edbg_recv_frame): Return correct length as
+	reported in the response packet, rather than full 512 byte which
+	are always reported by the CMSIS-DAP layer.  Miscalculations
+	based on the wrongly reported length caused heap corruption
+	elsewhere, so this is presumably also a fix for bug #43078.
+
 2014-11-20  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	bug #41561: AVRDUDE 6.0.1/USBasp doesn't write first bytes of
diff --git a/NEWS b/NEWS
index ea8cf844..153da680 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ Current:
                   after changing lock byte
     - bug #41561: AVRDUDE 6.0.1/USBasp doesn't write first bytes of
                   flash page
+    - bug #43078: AVRDUDE crashes after sucessfully reading/writing eeprom
 
   * Internals:
     - ...
diff --git a/jtag3.c b/jtag3.c
index 3cb3c6f1..f0fae0f3 100644
--- a/jtag3.c
+++ b/jtag3.c
@@ -690,7 +690,7 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
 
   *msg = buf;
 
-  return rv;
+  return len;
 }
 
 int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {