diff --git a/ChangeLog b/ChangeLog
index 1d98acd9..132c169a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-09-02  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
+
+	bug #38023: avrdude doesn't return an error code when attempting
+	to upload an invalid Intel HEX file
+	* fileio.c (ihex2b): Turn the "No end of file record found" warning
+	into an error if no valid record was found at all.
+
 2013-09-02  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	Submitted by Claus-Justus Heine:
diff --git a/NEWS b/NEWS
index a80225ed..51f4b43d 100644
--- a/NEWS
+++ b/NEWS
@@ -82,6 +82,8 @@ Current:
         is enabled AND target has a very slow clock
       - bug #39893: Verification failure with AVRISPmkII and Xmega
       - bug #38713: Compilation of the documentation breaks with texinfo-5
+      - bug #38023: avrdude doesn't return an error code when attempting
+        to upload an invalid Intel HEX file
 
   * Keep track of input file contents
 
diff --git a/fileio.c b/fileio.c
index c5dd7b90..ffd112a2 100644
--- a/fileio.c
+++ b/fileio.c
@@ -372,12 +372,22 @@ static int ihex2b(char * infile, FILE * inf,
 
   } /* while */
 
-  fprintf(stderr, 
-          "%s: WARNING: no end of file record found for Intel Hex "
-          "file \"%s\"\n",
-          progname, infile);
+  if (maxaddr == 0) {
+    fprintf(stderr, 
+	    "%s: ERROR: No valid record found in Intel Hex "
+	    "file \"%s\"\n",
+	    progname, infile);
 
-  return maxaddr;
+    return -1;
+  }
+  else {
+    fprintf(stderr, 
+	    "%s: WARNING: no end of file record found for Intel Hex "
+	    "file \"%s\"\n",
+	    progname, infile);
+
+    return maxaddr;
+  }
 }
 
 static int b2srec(unsigned char * inbuf, int bufsize,