From: Jeffrey Bencteux Date: Wed, 21 Jun 2023 13:12:43 +0000 (+0200) Subject: chgpasswd: fix segfault in command-line options X-Git-Tag: 4.14.0-rc1~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53a17c1742a4b5fcf9280fd6dd85fc77588535c2;p=thirdparty%2Fshadow.git chgpasswd: fix segfault in command-line options Using the --sha-rounds option without first giving a crypt method via the --crypt-method option results in comparisons with a NULL pointer and thus make chgpasswd segfault: $ chgpasswd -s 1 zsh: segmentation fault chgpasswd -s 1 Current patch add a sanity check before these comparisons to ensure there is a defined encryption method. --- diff --git a/src/chgpasswd.c b/src/chgpasswd.c index fe4055d8a..7b773e2ff 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -186,6 +186,13 @@ static void process_flags (int argc, char **argv) case 's': sflg = true; bad_s = 0; + + if (!crypt_method) { + fprintf (stderr, + _("%s: no crypt method defined\n"), + Prog); + usage (E_USAGE); + } #if defined(USE_SHA_CRYPT) if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512"))) && (0 == getlong(optarg, &sha_rounds)))) {