pgbench: fix segfault with empty sql file
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 12 Feb 2016 20:14:45 +0000 (17:14 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 12 Feb 2016 20:14:45 +0000 (17:14 -0300)
Commit 1d0c3b3f8a introduced a bug that causes pgbench to crash if an
empty script file is specified.  Fix it by rejecting such files at
startup, which is the historical and intended behavior.

Reported-By: Jeff Janes
Discussion: https://www.postgresql.org/message-id/CAMkU=1zxKUbLPOt9hQWFp14pTc=V0cGo2GQBbn2GsK2Pu+8ZfA@mail.gmail.com

src/bin/pgbench/pgbench.c

index 7eb6a2dea2747d43f61198aacd1b79117e1c44ca..2c0a3182d34625814381dc6954f8f93204bbd82d 100644 (file)
@@ -2686,7 +2686,8 @@ findBuiltin(const char *name, char **desc)
 static void
 addScript(const char *name, Command **commands)
 {
-   if (commands == NULL)
+   if (commands == NULL ||
+       commands[0] == NULL)
    {
        fprintf(stderr, "empty command list for script \"%s\"\n", name);
        exit(1);