]> granicus.if.org Git - postgresql/commitdiff
Fix psql crash while parsing SQL file whose encoding is different from
authorTatsuo Ishii <ishii@postgresql.org>
Sun, 2 Dec 2012 12:11:15 +0000 (21:11 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Sun, 2 Dec 2012 12:11:15 +0000 (21:11 +0900)
client encoding and the client encoding is not *safe* one. Such an
example is, file encoding is UTF-8 and client encoding SJIS. Patch
contributed by Jiang Guiqing.

src/bin/psql/psqlscan.l

index d32a12c63c856625aa42c708b24d4b58e3cdd677..6c1429815f2eec597f735d18ea86d9c8c9f1f3a2 100644 (file)
@@ -1807,7 +1807,7 @@ prepare_buffer(const char *txt, int len, char **txtcopy)
                        /* first byte should always be okay... */
                        newtxt[i] = txt[i];
                        i++;
-                       while (--thislen > 0)
+                       while (--thislen > 0 && i < len)
                                newtxt[i++] = (char) 0xFF;
                }
        }