Select Git revision
passbook.c 16.03 KiB
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <pwd.h>
#include <unistd.h>
#include "debug.h"
#ifdef PASSBOOK_LIBFUZZER
#include <stdint.h>
const char LIBFUZZER_INPUT_FILE[] = "libFuzzerInput.tmp";
/* turn off tracing to make it run faster */
#define printf(...)
#define fprintf(...)
#endif
const char INSTRUCTION_PUT[] = "put";
const char INSTRUCTION_REM[] = "rem";
const char INSTRUCTION_GET[] = "get";
const char INSTRUCTION_SAVE[] = "save";
const char INSTRUCTION_LIST[] = "list";
const char INSTRUCTION_MASTERPW[] = "masterpw";
/* a credential is a username/password pair */
typedef struct {
char * username;
char * password;
} cred_t;
/* we store a mapping from URLs to credentials using a binary tree
to try to ensure log lookup performance */
typedef struct node {
char * url;
cred_t cred;
struct node *left;
struct node *right;
} node_t;
static const node_t * lookup(const node_t *p, const char *url){
while (p != NULL){
int ret = strcmp(url,p->url);
if (ret == 0){
return p;
}else if (ret < 0){
p = p->left;
}else{
p = p->right;
}
}
return p; // not found
}
#define VALID_USERNAME_LENGTH 1014
static void node_print(const node_t *p){
printf("URL: %s, Username: %s, Password: %s\n",p->url,p->cred.username,p->cred.password);
}
/* construct a new node */
static node_t *node_new(const char *url, const cred_t cred){
node_t *new = malloc(sizeof(node_t));
assert(new != NULL && "new: malloc failed");
new->url = strdup(url);
assert(new->url != NULL && "new: strdup url failed");
// new->cred.username = strdup(cred.username);