2
0

No color fixes & malloc bug in .mpw reading.

[FIXED]     We weren't properly excluding all dependencies on ncurses when colors are not enabled.
[FIXED]     There was a memory realloc bug when reading multiple lines from ~/.mpw.
This commit is contained in:
Maarten Billemont 2014-12-02 20:46:53 -05:00
parent 3db25e7e3b
commit c48fba6c01
2 changed files with 13 additions and 11 deletions

View File

@ -199,12 +199,15 @@ int main(int argc, char *const argv[]) {
char *line = NULL;
size_t linecap = 0;
ssize_t linelen;
while ((linelen = getline(&line, &linecap, mpwConfig)) > 0)
if (strcmp(strsep(&line, ":"), userName) == 0) {
masterPassword = strsep(&line, "\n");
while ((linelen = getline(&line, &linecap, mpwConfig)) > 0) {
char *lineData = line;
if (strcmp(strsep(&lineData, ":"), userName) == 0) {
masterPassword = strsep(&lineData, "\n");
break;
}
}
free(line);
}
while (!masterPassword)
masterPassword = getpass( "Your master password: " );
trc("masterPassword: %s\n", masterPassword);

View File

@ -15,8 +15,10 @@
#include <alg/sha256.h>
#ifdef COLOR
#include <curses.h>
#include <term.h>
#endif
#include "types.h"
@ -222,15 +224,10 @@ const char *Identicon(const char *userName, const char *masterPassword) {
uint8_t identiconSeed[32];
HMAC_SHA256_Buf(masterPassword, strlen(masterPassword), userName, strlen(userName), identiconSeed);
bool useColor = 0;
#ifdef COLOR
if (isatty(STDERR_FILENO))
useColor = 1;
#endif
uint8_t colorIdentifier = identiconSeed[4] % 7 + 1;
char *colorString, *resetString;
if (useColor) {
#ifdef COLOR
if (isatty( STDERR_FILENO )) {
initputvar();
tputs(tparm(tgetstr("AF", NULL), colorIdentifier), 1, putvar);
colorString = calloc(strlen(putvarc) + 1, sizeof(char));
@ -238,7 +235,9 @@ const char *Identicon(const char *userName, const char *masterPassword) {
tputs(tgetstr("me", NULL), 1, putvar);
resetString = calloc(strlen(putvarc) + 1, sizeof(char));
strcpy(resetString, putvarc);
} else {
} else
#endif
{
colorString = calloc(1, sizeof(char));
resetString = calloc(1, sizeof(char));
}