diff options
author | Mikhail Teterin <mi@FreeBSD.org> | 2002-01-09 20:49:02 +0000 |
---|---|---|
committer | Mikhail Teterin <mi@FreeBSD.org> | 2002-01-09 20:49:02 +0000 |
commit | 6c09982b17ab943af46cd13ff77c58fba3868e3f (patch) | |
tree | e724e8bde9609cd26232c722932a9745e077f23a /security/pam-pgsql/files | |
parent | Remove the dependency on security/mhash by calling MD5Data directly. (diff) |
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/
Notes
Notes:
svn path=/head/; revision=52829
Diffstat (limited to 'security/pam-pgsql/files')
-rw-r--r-- | security/pam-pgsql/files/Makefile.bsd | 5 | ||||
-rw-r--r-- | security/pam-pgsql/files/pqescape.c | 66 |
2 files changed, 70 insertions, 1 deletions
diff --git a/security/pam-pgsql/files/Makefile.bsd b/security/pam-pgsql/files/Makefile.bsd index 90e58ccb38f7..cef112fc21d8 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 000000000000..c13304e0a204 --- /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) */ |