Skip to content

Commit a93e318

Browse files
committed
Added space for 'pycmd' string termination needed by 'strncat' and replaced 'sprintf' with 'strncat'
1 parent f698e24 commit a93e318

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mig/src/libpam-mig/migauthhandler.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ static bool mig_reg_auth_attempt(const unsigned int mode,
368368
/* We don't exit hard here to make sure other auth types may follow */
369369
return false;
370370
}
371-
char pycmd[MAX_PYCMD_LENGTH] =
371+
/* NOTE: Allocate space for string terminator '\0' added by strncat after concatenation */
372+
char pycmd[MAX_PYCMD_LENGTH+1] =
372373
"(authorized, disconnect) = validate_auth_attempt(configuration, 'sftp-subsys', ";
373-
char pytmp[MAX_PYCMD_LENGTH];
374374
/* Always password auth here as mentioned in the above comment */
375375
strncat(&pycmd[0], "'password', ", MAX_PYCMD_LENGTH - strlen(pycmd));
376376

@@ -380,8 +380,9 @@ static bool mig_reg_auth_attempt(const unsigned int mode,
380380
strncat(&pycmd[0], address, MAX_PYCMD_LENGTH - strlen(pycmd));
381381
strncat(&pycmd[0], "', ", MAX_PYCMD_LENGTH - strlen(pycmd));
382382
if (secret != NULL) {
383-
sprintf(&pytmp[0], "secret='%s', ", secret);
384-
strncat(&pycmd[0], &pytmp[0], MAX_PYCMD_LENGTH - strlen(pycmd));
383+
strncat(&pycmd[0], "secret='", MAX_PYCMD_LENGTH - strlen(pycmd));
384+
strncat(&pycmd[0], secret, MAX_PYCMD_LENGTH - strlen(pycmd));
385+
strncat(&pycmd[0], "', ", MAX_PYCMD_LENGTH - strlen(pycmd));
385386
}
386387
if (mode & MIG_INVALID_USERNAME) {
387388
strncat(&pycmd[0], "invalid_username=True, ",

0 commit comments

Comments
 (0)