summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authormi <mi@FreeBSD.org>2002-01-09 20:49:02 +0000
committermi <mi@FreeBSD.org>2002-01-09 20:49:02 +0000
commit13c083ac877efc66cb24a7df517f5a4d166fcf57 (patch)
tree6108503b77b551ba1162c58bd97e9b84b69a3056 /security
parentf2af7c7730e7fe4eb3ed495b842b14a9c8703dc5 (diff)
downloadFreeBSD-ports-13c083ac877efc66cb24a7df517f5a4d166fcf57.zip
FreeBSD-ports-13c083ac877efc66cb24a7df517f5a4d166fcf57.tar.gz
Close the security hole by making it escape all of the untrusted input
before passing it to the SQL server. The code in the added pqescape.c is going to be in the next PostgreSQL release, but it is not there yet and this port will use its own private copy for now. No REVISION bump since the port was forbidden ever since the last upgrade. Submitter reviewed my tweaks of his patch and approved them authorizing (as one of the SOs) the removal of the FORBIDDEN flag. Submitted by: nectar Reviewed by: nectar Approved by: nectar Obtained from: http://CERT.uni-stuttgart.de/doc/postgresql/escape/
Diffstat (limited to 'security')
-rw-r--r--security/pam-pgsql/Makefile4
-rw-r--r--security/pam-pgsql/files/Makefile.bsd5
-rw-r--r--security/pam-pgsql/files/pqescape.c66
3 files changed, 71 insertions, 4 deletions
diff --git a/security/pam-pgsql/Makefile b/security/pam-pgsql/Makefile
index 837c2ad..885b70c 100644
--- a/security/pam-pgsql/Makefile
+++ b/security/pam-pgsql/Makefile
@@ -16,8 +16,6 @@ MAINTAINER= mi@aldan.algebra.com
LIB_DEPENDS= pq:${PORTSDIR}/databases/postgresql7
-FORBIDDEN= can be broken by carefully crafted password string
-
# When the family of Debian mirrors is added to bsd.port.mk,
# this will suddenly start making sense:
MASTER_SITE_DEBIAN?= http://ftp.debian.org/debian/%SUBDIR%/
@@ -29,7 +27,7 @@ MASTER_SITES_DEBIAN+= http://ftp.au.debian.org/pub/debian/%SUBDIR%/ \
ftp://ftp.bora.net/pub/linux/debian/%SUBDIR%/
MAKEFILE= ${FILESDIR}/Makefile.bsd
-MAKE_ARGS+= -j 2
+MAKE_ARGS+= -j 2 FILESDIR=${FILESDIR}
post-install:
${CAT} ${PKGMESSAGE}
diff --git a/security/pam-pgsql/files/Makefile.bsd b/security/pam-pgsql/files/Makefile.bsd
index 90e58cc..cef112f 100644
--- a/security/pam-pgsql/files/Makefile.bsd
+++ b/security/pam-pgsql/files/Makefile.bsd
@@ -1,6 +1,9 @@
# This makefile is inspired by those in /usr/src/lib/libpam/modules :-)
-SRCS= pam_pgsql.c pam_get_pass.c pam_std_option.c pam_get_service.c
+.PATH: ${FILESDIR}
+
+SRCS= pam_pgsql.c pam_get_pass.c pam_std_option.c pam_get_service.c \
+ pqescape.c
LIB= pam_pgsql
SHLIB_NAME=${LIB}.so
diff --git a/security/pam-pgsql/files/pqescape.c b/security/pam-pgsql/files/pqescape.c
new file mode 100644
index 0000000..c13304e
--- /dev/null
+++ b/security/pam-pgsql/files/pqescape.c
@@ -0,0 +1,66 @@
+/*
+ * PQescapeString implementation is from
+ * <URL:http://cert.uni-stuttgart.de/doc/postgresql/escape/>
+ * It will be available in a later release of PostGreSQL.
+ */
+#if !defined(HAVE_PQESCAPESTRING)
+#include <sys/types.h>
+
+/* Quoting strings before inclusion in queries. */
+size_t PQescapeString (char *to, const char *from, size_t length);
+
+/* ---------------
+ * Escaping arbitrary strings to get valid SQL strings/identifiers.
+ *
+ * Replaces "\\" with "\\\\", "\0" with "\\0", and "'" with "''".
+ * length is the length of the buffer pointed to by
+ * from. The buffer at to must be at least 2*length + 1 characters
+ * long. A terminating NUL character is written.
+ * ---------------
+ */
+
+size_t
+PQescapeString (char *to, const char *from, size_t length)
+{
+ const char *source = from;
+ char *target = to;
+ unsigned int remaining = length;
+
+ while (remaining > 0) {
+ switch (*source) {
+ case '\0':
+ *target = '\\';
+ target++;
+ *target = '0';
+ /* target and remaining are updated below. */
+ break;
+
+ case '\\':
+ *target = '\\';
+ target++;
+ *target = '\\';
+ /* target and remaining are updated below. */
+ break;
+
+ case '\'':
+ *target = '\'';
+ target++;
+ *target = '\'';
+ /* target and remaining are updated below. */
+ break;
+
+ default:
+ *target = *source;
+ /* target and remaining are updated below. */
+ }
+ source++;
+ target++;
+ remaining--;
+ }
+
+ /* Write the terminating NUL character. */
+ *target = '\0';
+
+ return target - to;
+}
+#endif /* !defined(HAVE_PQESCAPESTRING) */
OpenPOWER on IntegriCloud