Skip to content

Commit

Permalink
chgpasswd: avoid NULL dereference
Browse files Browse the repository at this point in the history
A crypt method needs to be specified before the rounds can set:

    #0  __strcmp_sse42 () at ../sysdeps/x86_64/multiarch/strcmp-sse4_2.S:227
    shadow-maint#1  0x0000555555557755 in process_flags (argv=0x7fffffffe4d8, argc=3) at chgpasswd.c:188
    shadow-maint#2  main (argc=3, argv=0x7fffffffe4d8) at chgpasswd.c:427

    chgpasswd.c:188:42: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
  • Loading branch information
cgzones committed Jan 30, 2023
1 parent 3b1905f commit 10b85ad
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/chgpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ static void process_flags (int argc, char **argv)
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
case 's':
sflg = true;
bad_s = 0;
bad_s = 0;
if (!crypt_method) {
fprintf (stderr,
_("%s: --sha-rounds requires --crypt-method to be specified\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)))) {
Expand Down

0 comments on commit 10b85ad

Please sign in to comment.