Browse Source

Bug 1998: Failure when reading a key file without a trailing newline

https://winscp.net/tracker/1998
(cherry picked from commit 310ecc06c3090cc9e11b5ef1101615f8ff569fc1)

Source commit: b7c594fd36ecf26755209cbf639a207c17734937
Martin Prikryl 4 years ago
parent
commit
248548af34
1 changed files with 4 additions and 4 deletions
  1. 4 4
      source/putty/sshpubk.c

+ 4 - 4
source/putty/sshpubk.c

@@ -496,7 +496,7 @@ static bool read_header(BinarySource *src, char *header)
 
     while (1) {
         c = get_byte(src);
-        if (c == '\n' || c == '\r' || c == EOF)
+        if (c == '\n' || c == '\r' || get_err(src))
             return false;              /* failure */
         if (c == ':') {
             c = get_byte(src);
@@ -519,10 +519,10 @@ static char *read_body(BinarySource *src)
 
     while (1) {
         int c = get_byte(src);
-        if (c == '\r' || c == '\n' || c == EOF) {
-            if (c != EOF) {
+        if (c == '\r' || c == '\n' || get_err(src)) {
+            if (!get_err(src)) {
                 c = get_byte(src);
-                if (c != '\r' && c != '\n')
+                if (c != '\r' && c != '\n' && !get_err(src))
                     src->pos--;
             }
             return strbuf_to_str(buf);