8
8
9
9
#include <config.h>
10
10
11
+ #include <errno.h>
11
12
#include <limits.h>
12
13
#include <readpassphrase.h>
14
+ #include <stddef.h>
13
15
#include <stdlib.h>
14
16
#include <string.h>
15
17
22
24
23
25
24
26
// Similar to getpass(3), but free of its problems.
25
- #define agetpass (prompt ) agetpass_internal(prompt, RPP_REQUIRE_TTY)
26
- #define agetpass_stdin () agetpass_internal(NULL, RPP_STDIN)
27
+ #define agetpass (prompt ) agetpass_(prompt, RPP_REQUIRE_TTY)
28
+ #define agetpass_stdin () agetpass_(NULL, RPP_STDIN)
29
+
30
+ #define agetpass_ (...) getpass_(MALLOC(PASS_MAX + 2, char), __VA_ARGS__)
27
31
28
32
29
33
inline void erase_pass (char * pass );
30
34
ATTR_MALLOC (erase_pass )
31
- inline char * agetpass_internal ( const char * prompt , int flags );
35
+ inline char * getpass_ ( char pass [ PASS_MAX + 2 ], const char * prompt , int flags );
32
36
33
37
34
38
inline char *
35
- agetpass_internal ( const char * prompt , int flags )
39
+ getpass_ ( char pass [ PASS_MAX + 2 ], const char * prompt , int flags )
36
40
{
37
- char * pass ;
38
41
size_t len ;
39
42
43
+ if (pass == NULL )
44
+ return NULL ;
45
+
40
46
/*
41
47
* Since we want to support passwords upto PASS_MAX, we need
42
48
* PASS_MAX bytes for the password itself, and one more byte for
@@ -45,10 +51,6 @@ agetpass_internal(const char *prompt, int flags)
45
51
* Let's add one more byte, and if the password uses it, it
46
52
* means the introduced password was longer than PASS_MAX.
47
53
*/
48
- pass = MALLOC (PASS_MAX + 2 , char );
49
- if (pass == NULL )
50
- return NULL ;
51
-
52
54
if (readpassphrase (prompt , pass , PASS_MAX + 2 , flags ) == NULL )
53
55
goto fail ;
54
56
0 commit comments