e5cfd7
Index: shadow-4.5/src/usermod.c
e5cfd7
===================================================================
e5cfd7
--- shadow-4.5.orig/src/usermod.c
e5cfd7
+++ shadow-4.5/src/usermod.c
e5cfd7
@@ -455,14 +455,17 @@ static char *new_pw_passwd (char *pw_pas
e5cfd7
 		strcat (buf, pw_pass);
e5cfd7
 		pw_pass = buf;
e5cfd7
 	} else if (Uflg && pw_pass[0] == '!') {
e5cfd7
-		char *s;
e5cfd7
+		char *s = pw_pass;
e5cfd7
 
e5cfd7
-		if (pw_pass[1] == '\0') {
e5cfd7
+		while ('!' == *s)
e5cfd7
+			++s;
e5cfd7
+
e5cfd7
+		if (*s == '\0') {
e5cfd7
 			fprintf (stderr,
e5cfd7
 			         _("%s: unlocking the user's password would result in a passwordless account.\n"
e5cfd7
 			           "You should set a password with usermod -p to unlock this user's password.\n"),
e5cfd7
 			         Prog);
e5cfd7
-			return pw_pass;
e5cfd7
+			return NULL;
e5cfd7
 		}
e5cfd7
 
e5cfd7
 #ifdef WITH_AUDIT
e5cfd7
@@ -471,12 +474,15 @@ static char *new_pw_passwd (char *pw_pas
e5cfd7
 		              user_newname, (unsigned int) user_newid, 1);
e5cfd7
 #endif
e5cfd7
 		SYSLOG ((LOG_INFO, "unlock user '%s' password", user_newname));
e5cfd7
-		s = pw_pass;
e5cfd7
-		while ('\0' != *s) {
e5cfd7
-			*s = *(s + 1);
e5cfd7
-			s++;
e5cfd7
-		}
e5cfd7
+		memmove (pw_pass, s, strlen (s) + 1);
e5cfd7
 	} else if (pflg) {
e5cfd7
+		if (strchr (user_pass, ':') != NULL) {
e5cfd7
+			fprintf (stderr,
e5cfd7
+			         _("%s: The password field cannot contain a colon character.\n"),
e5cfd7
+			         Prog);
e5cfd7
+			return NULL;
e5cfd7
+
e5cfd7
+		}
e5cfd7
 #ifdef WITH_AUDIT
e5cfd7
 		audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
e5cfd7
 		              "updating-password",
e5cfd7
@@ -525,6 +531,8 @@ static void new_pwent (struct passwd *pw
e5cfd7
 	if (   (!is_shadow_pwd)
e5cfd7
 	    || (strcmp (pwent->pw_passwd, SHADOW_PASSWD_STRING) != 0)) {
e5cfd7
 		pwent->pw_passwd = new_pw_passwd (pwent->pw_passwd);
e5cfd7
+		if (pwent->pw_passwd == NULL)
e5cfd7
+			fail_exit (E_PW_UPDATE);
e5cfd7
 	}
e5cfd7
 
e5cfd7
 	if (uflg) {
e5cfd7
@@ -639,6 +647,8 @@ static void new_spent (struct spwd *spen
e5cfd7
 	 *  + aging has been requested
e5cfd7
 	 */
e5cfd7
 	spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp);
e5cfd7
+	if (spent->sp_pwdp == NULL)
e5cfd7
+		fail_exit(E_PW_UPDATE);
e5cfd7
 
e5cfd7
 	if (pflg) {
e5cfd7
 		spent->sp_lstchg = (long) gettime () / SCALE;