8
8
9
9
#include <config.h>
10
10
11
+ #include <alloca.h>
12
+ #include <errno.h>
11
13
#include <limits.h>
12
14
#include <readpassphrase.h>
15
+ #include <stddef.h>
13
16
#include <stdlib.h>
14
17
#include <string.h>
15
18
16
19
#include "alloc/malloc.h"
17
-
18
- #if WITH_LIBBSD == 0
19
- #include "freezero.h"
20
- #endif /* WITH_LIBBSD */
20
+ #include "memzero.h"
21
21
22
22
23
23
// Similar to getpass(3), but free of its problems.
24
- #define agetpass (prompt ) agetpass_internal(prompt, RPP_REQUIRE_TTY)
25
- #define agetpass_stdin () agetpass_internal(NULL, RPP_STDIN)
24
+ #define agetpass (prompt ) agetpass_(prompt, RPP_REQUIRE_TTY)
25
+ #define agetpass_stdin () agetpass_(NULL, RPP_STDIN)
26
+
27
+ #define agetpass_ (...) getpass_(alloca(PASS_MAX + 2), __VA_ARGS__)
26
28
27
29
28
30
inline void erase_pass (char * pass );
29
31
ATTR_MALLOC (erase_pass )
30
- inline char * agetpass_internal ( const char * prompt , int flags );
32
+ inline char * getpass_ ( char pass [ PASS_MAX + 2 ], const char * prompt , int flags );
31
33
32
34
33
35
inline char *
34
- agetpass_internal ( const char * prompt , int flags )
36
+ getpass_ ( char pass [ PASS_MAX + 2 ], const char * prompt , int flags )
35
37
{
36
- char * pass ;
37
38
size_t len ;
38
39
39
40
/*
@@ -44,10 +45,6 @@ agetpass_internal(const char *prompt, int flags)
44
45
* Let's add one more byte, and if the password uses it, it
45
46
* means the introduced password was longer than PASS_MAX.
46
47
*/
47
- pass = MALLOC (PASS_MAX + 2 , char );
48
- if (pass == NULL )
49
- return NULL ;
50
-
51
48
if (readpassphrase (prompt , pass , PASS_MAX + 2 , flags ) == NULL )
52
49
goto fail ;
53
50
@@ -60,15 +57,15 @@ agetpass_internal(const char *prompt, int flags)
60
57
return pass ;
61
58
62
59
fail :
63
- freezero (pass , PASS_MAX + 2 );
60
+ memzero (pass , PASS_MAX + 2 );
64
61
return NULL ;
65
62
}
66
63
67
64
68
65
inline void
69
66
erase_pass (char * pass )
70
67
{
71
- freezero (pass , PASS_MAX + 2 );
68
+ memzero (pass , PASS_MAX + 2 );
72
69
}
73
70
74
71
0 commit comments