Fix ^Ding out of the new passphrase prompt

This commit is contained in:
наб 2022-12-04 01:37:56 +01:00
parent b5ff262534
commit 720a0103a7
No known key found for this signature in database
GPG Key ID: BCFD0B018D2658F1
2 changed files with 6 additions and 5 deletions

View File

@ -5,6 +5,7 @@
#include "main.hpp"
#include <utility>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
@ -200,7 +201,7 @@ static int get_key_material_raw(const char * whom, bool again, bool newkey, uint
auto bytes = getline((char **)&buf, &buflen, stdin);
switch(bytes) {
case -1:
if(errno != 0)
if(errno)
TRY("read in passphrase", bytes);
else // EOF
bytes = 0;
@ -269,10 +270,9 @@ int read_new_passphrase(const char * whom, uint8_t *& buf, size_t & len_out, siz
if(second_passphrase_len != first_passphrase_len || memcmp(first_passphrase, second_passphrase, first_passphrase_len))
return fprintf(stderr, "Provided keys do not match.\n"), __LINE__;
if(second_passphrase_len) {
buf = second_passphrase;
second_passphrase = nullptr;
} else
if(second_passphrase_len)
buf = std::exchange(second_passphrase, nullptr);
else
buf = nullptr;
len_out = second_passphrase_len;

View File

@ -16,6 +16,7 @@ int with_stdin_at(int fd, F && what) {
TRY("dup2() onto stdin", dup2(fd, 0));
clearerr(stdin);
if(int ret = what()) {
dup2(stdin_saved, 0);
return ret;