Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VXxYd-0000sQ-Ai for pgsql-bugs@arkaria.postgresql.org; Sun, 20 Oct 2013 18:16:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VXxYc-000351-JF for pgsql-bugs@arkaria.postgresql.org; Sun, 20 Oct 2013 18:16:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VXeOY-0002wn-Ot for pgsql-bugs@postgresql.org; Sat, 19 Oct 2013 21:49:14 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VXeOW-0007wN-7L for pgsql-bugs@postgresql.org; Sat, 19 Oct 2013 21:49:14 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by mahout.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VXeOV-0004Ne-4c for pgsql-bugs@postgresql.org; Sat, 19 Oct 2013 21:49:11 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1VXeOP-0002cc-Ow for pgsql-bugs@postgresql.org; Sat, 19 Oct 2013 21:49:05 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: BUG #8540: Avoid sscanf buffer overflow To: pgsql-bugs@postgresql.org From: jackie.qq.chang@gmail.com Message-Id: Date: Sat, 19 Oct 2013 21:49:05 +0000 X-Pg-Spam-Score: -1.4 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 8540 Logged by: Jackie Chang Email address: jackie.qq.chang@gmail.com PostgreSQL version: 9.3.1 Operating system: Any Description: sscanf can set the maximum length of string read. If such a number is not provided, it's vulnerable to buffer overflow. Diff is: diff --git a/contrib/pg_upgrade/option.c b/contrib/pg_upgrade/option.c index 250aeb8..293ef1c 100644 --- a/contrib/pg_upgrade/option.c +++ b/contrib/pg_upgrade/option.c @@ -443,7 +443,7 @@ get_sock_dir(ClusterInfo *cluster, bool live_check) { cluster->sockdir = pg_malloc(MAXPGPATH); /* strip off newline */ - sscanf(line, "%s\n", cluster->sockdir); + sscanf(line, "%1023s\n", cluster->sockdir); } } fclose(fp); diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 06f5eb0..560230f 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -10029,7 +10029,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p) * Read and parse the START WAL LOCATION line (this code is pretty crude, * but we are not expecting any variability in the file format). */ - if (sscanf(labelfile, "START WAL LOCATION: %X/%X (file %24s)%c", + if (sscanf(labelfile, "START WAL LOCATION: %X/%X (file %63s)%c", &hi, &lo, startxlogfilename, &ch) != 4 || ch != '\n') ereport(ERROR, diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c index f803186..48e0db9 100644 --- a/src/bin/pg_dump/pg_backup_directory.c +++ b/src/bin/pg_dump/pg_backup_directory.c @@ -452,7 +452,7 @@ _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt) char fname[MAXPGPATH]; char path[MAXPGPATH]; - if (sscanf(line, "%u %s\n", &oid, fname) != 2) + if (sscanf(line, "%u %1023s\n", &oid, fname) != 2) exit_horribly(modulename, "invalid line in large object TOC file \"%s\": \"%s\"\n", fname, line); -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs