From a01f6eaec9ff2a3b4ec649be375cba93c43e1646 Mon Sep 17 00:00:00 2001
From: Bryan Drewery <bdrewery@FreeBSD.org>
Date: Thu, 14 Mar 2013 10:11:34 +0000
Subject: - Fix crash in pkg-update   You may need to manually 'pkg add'
 1.0.9_1 or rebuild   from ports if you are on 1.0.9

Submitted by:	Alexandre Perrin <alexandre.perrin@netoxygen.ch>
Obtained from:	upstream git
With hat:	portmgr
---
 ports-mgmt/pkg/Makefile                    |  1 +
 ports-mgmt/pkg/files/patch-libpkg__pkgdb.c | 28 ++++++++++++++++++++++++++++
 ports-mgmt/pkg/files/patch-newvers.sh      | 19 +++++++++++++++++++
 3 files changed, 48 insertions(+)
 create mode 100644 ports-mgmt/pkg/files/patch-libpkg__pkgdb.c
 create mode 100644 ports-mgmt/pkg/files/patch-newvers.sh

diff --git a/ports-mgmt/pkg/Makefile b/ports-mgmt/pkg/Makefile
index e053a1fc4892..0708bf8fb72e 100644
--- a/ports-mgmt/pkg/Makefile
+++ b/ports-mgmt/pkg/Makefile
@@ -2,6 +2,7 @@
 
 PORTNAME=	pkg
 DISTVERSION=	1.0.9
+PORTREVISION=	1
 CATEGORIES=	ports-mgmt
 MASTER_SITES=	LOCAL/portmgr \
 		http://files.etoilebsd.net/pkg/
diff --git a/ports-mgmt/pkg/files/patch-libpkg__pkgdb.c b/ports-mgmt/pkg/files/patch-libpkg__pkgdb.c
new file mode 100644
index 000000000000..293338866b14
--- /dev/null
+++ b/ports-mgmt/pkg/files/patch-libpkg__pkgdb.c
@@ -0,0 +1,28 @@
+commit 6bf8c2d025e30e5635e6648f35ff8dcbc7c4709c
+Author: Alexandre Perrin <alexandre.perrin@netoxygen.ch>
+Date:   Tue Mar 5 12:04:44 2013 +0100
+
+    check the return value of sqlite3_column_text() against NULL in get_sql_string()
+    
+    The return value of sqlite3_column_text() was not checked and passed
+    directly to strdup() causing a SIGSEV from libc. This patch ensure that
+    a NULL returned value will not be given to strdup().
+
+diff --git libpkg/pkgdb.c libpkg/pkgdb.c
+index 7140a69..7a2c706 100644
+--- libpkg/pkgdb.c
++++ libpkg/pkgdb.c
+@@ -2413,8 +2413,11 @@ get_sql_string(sqlite3 *s, const char *sql, char **res)
+ 
+ 	ret = sqlite3_step(stmt);
+ 
+-	if (ret == SQLITE_ROW)
+-		*res = strdup(sqlite3_column_text(stmt, 0));
++	if (ret == SQLITE_ROW) {
++		const unsigned char *tmp;
++		tmp = sqlite3_column_text(stmt, 0);
++		*res = (tmp == NULL ? NULL : strdup(tmp));
++	}
+ 
+ 	if (ret == SQLITE_DONE)
+ 		*res = NULL;
diff --git a/ports-mgmt/pkg/files/patch-newvers.sh b/ports-mgmt/pkg/files/patch-newvers.sh
new file mode 100644
index 000000000000..d0366a9f9b9c
--- /dev/null
+++ b/ports-mgmt/pkg/files/patch-newvers.sh
@@ -0,0 +1,19 @@
+commit de8b5d86da60b0e25fddf5c69a60b6905ab941c4
+Author: Bryan Drewery <bryan@shatow.net>
+Date:   Thu Mar 14 05:00:26 2013 -0500
+
+    Bump to 1.0.9_1
+
+diff --git newvers.sh newvers.sh
+index e034c10..0712689 100755
+--- newvers.sh
++++ newvers.sh
+@@ -41,7 +41,7 @@
+ : ${PKG_MINOR_VERSION="0"}
+ : ${PKG_PATCH_LEVEL="9"}
+  
+-: ${PORTREVISION:=}
++: ${PORTREVISION:="1"}
+ : ${PORTEPOCH:=}
+ 
+ # ------------------------------------------------------------------
-- 
cgit debian/1.2.3+git2.25.1-1-2-gaceb0