]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
* htdbm/htpasswd: fix handling of crypt() failures.
authorWilliam A. Rowe Jr <wrowe@apache.org>
Tue, 21 Aug 2012 17:51:32 +0000 (17:51 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Tue, 21 Aug 2012 17:51:32 +0000 (17:51 +0000)
Backports: r1346905
Submitted by: Paul Wouters <pwouters redhat.com>, jorton
Reviewed by: rjung, trawick, wrowe

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@1375698 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
support/htdbm.c
support/htpasswd.c

diff --git a/CHANGES b/CHANGES
index a970684a746307f88d6e80fa67efc5e6bb850e90..d4117267507082a2cd5e8fca07e6e3f767feb0ba 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,9 @@ Changes with Apache 2.2.23
      possible XSS for a site where untrusted users can upload files to
      a location with MultiViews enabled. [Niels Heinen <heinenn google.com>]
 
+  *) htdbm, htpasswd: Don't crash if crypt() fails (e.g. with FIPS enabled). 
+     [Paul Wouters <pwouters redhat.com>, Joe Orton]
+
   *) mod_ldap: Treat the "server unavailable" condition as a transient
      error with all LDAP SDKs. [Filip Valder <filip.valder vsb.cz>]
 
diff --git a/STATUS b/STATUS
index 6df3bef33fa7e32e4258bdb95fc87e7c35299db4..3cb2ddfa603d967cc908306d0c669405d31428e4 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -93,11 +93,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-   * htdbm/htpasswd: fix handling of crypt() failures.
-     trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1346905
-     2.4.x patch: http://svn.apache.org/viewvc?view=revision&revision=1356887
-     2.2.x patch: http://people.apache.org/~rjung/patches/htdbm-htpasswd-handling_crypt_failure-2_2.patch
-     +1: rjung, trawick, wrowe
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]
index 5e4b8fb006d8fc3f13e9f0398b6c59e63d421a08..dd89d01b6c35a38fef723b4959d9bc41637456ab 100644 (file)
@@ -288,6 +288,9 @@ static apr_status_t htdbm_make(htdbm_t *htdbm)
 {
     char cpw[MAX_STRING_LEN];
     char salt[9];
+#if (!(defined(WIN32) || defined(NETWARE)))
+    char *cbuf;
+#endif
 
     switch (htdbm->alg) {
         case ALG_APSHA:
@@ -315,7 +318,15 @@ static apr_status_t htdbm_make(htdbm_t *htdbm)
             (void) srand((int) time((time_t *) NULL));
             to64(&salt[0], rand(), 8);
             salt[8] = '\0';
-            apr_cpystrn(cpw, (char *)crypt(htdbm->userpass, salt), sizeof(cpw) - 1);
+            cbuf = crypt(htdbm->userpass, salt);
+            if (cbuf == NULL) {
+                char errbuf[128];
+                
+                fprintf(stderr, "crypt() failed: %s\n", 
+                        apr_strerror(errno, errbuf, sizeof errbuf));
+                exit(ERR_PWMISMATCH);
+            }
+            apr_cpystrn(cpw, cbuf, sizeof(cpw) - 1);
             fprintf(stderr, "CRYPT is now deprecated, use MD5 instead!\n");
 #endif
         default:
index 3aa9e1845215757fbddc417b0c30241c46700a74..f218f794856b987e01b0fd1ebad457bc2c7e7f42 100644 (file)
@@ -166,6 +166,9 @@ static int mkrecord(char *user, char *record, apr_size_t rlen, char *passwd,
     char pwv[MAX_STRING_LEN];
     char salt[9];
     apr_size_t bufsize;
+#if (!(defined(WIN32) || defined(NETWARE)))
+    char *cbuf;
+#endif
 
     if (passwd != NULL) {
         pw = passwd;
@@ -218,7 +221,16 @@ static int mkrecord(char *user, char *record, apr_size_t rlen, char *passwd,
         to64(&salt[0], rand(), 8);
         salt[8] = '\0';
 
-        apr_cpystrn(cpw, crypt(pw, salt), sizeof(cpw) - 1);
+        cbuf = crypt(pw, salt);
+        if (cbuf == NULL) {
+            char errbuf[128];
+
+            apr_snprintf(record, rlen-1, "crypt() failed: %s", 
+                         apr_strerror(errno, errbuf, sizeof errbuf));
+            return ERR_PWMISMATCH;
+        }
+
+        apr_cpystrn(cpw, cbuf, sizeof(cpw) - 1);
         if (strlen(pw) > 8) {
             char *truncpw = strdup(pw);
             truncpw[8] = '\0';