Fix invalid pointer
This commit is contained in:
parent
274467fcf8
commit
d3e3123373
24
salty.c
24
salty.c
@ -116,7 +116,6 @@ int encryptMessage(const char* inputFile, const char* outputFile, const char* pa
|
|||||||
// Read input file
|
// Read input file
|
||||||
fprintf(stderr,NOR"Reading input filesize...\n");
|
fprintf(stderr,NOR"Reading input filesize...\n");
|
||||||
decLen = fileSize(inFile);
|
decLen = fileSize(inFile);
|
||||||
fprintf(stderr,OK"File is %d bytes.\n",decLen);
|
|
||||||
decrypted = malloc(decLen);
|
decrypted = malloc(decLen);
|
||||||
|
|
||||||
if (fread(decrypted,1,decLen,inFile) != decLen) {
|
if (fread(decrypted,1,decLen,inFile) != decLen) {
|
||||||
@ -129,7 +128,9 @@ int encryptMessage(const char* inputFile, const char* outputFile, const char* pa
|
|||||||
fclose(inFile);
|
fclose(inFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr,OK"Input read successfully!\n");
|
size_t encLen = decLen + crypto_secretbox_MACBYTES;
|
||||||
|
fprintf(stderr,OK"File is %d bytes.\n",decLen);
|
||||||
|
fprintf(stderr,OK"Encoding file to %d bytes.\n", encLen);
|
||||||
fprintf(stderr,NOR"Beginning encryption...\n");
|
fprintf(stderr,NOR"Beginning encryption...\n");
|
||||||
|
|
||||||
// Generate a nonce, write headers and encrypted message
|
// Generate a nonce, write headers and encrypted message
|
||||||
@ -137,11 +138,11 @@ int encryptMessage(const char* inputFile, const char* outputFile, const char* pa
|
|||||||
randombytes_buf(nonce,sizeof(nonce));
|
randombytes_buf(nonce,sizeof(nonce));
|
||||||
|
|
||||||
// Encrypt the data
|
// Encrypt the data
|
||||||
unsigned char encrypted[decLen + crypto_secretbox_MACBYTES];
|
unsigned char encrypted[encLen];
|
||||||
crypto_secretbox_easy(encrypted, decrypted, decLen, nonce, key);
|
crypto_secretbox_easy(encrypted, decrypted, decLen, nonce, key);
|
||||||
|
|
||||||
// Patchy but correct-ish attempt to solve annoying stdout issue
|
// Patchy but correct-ish attempt to solve annoying stdout issue
|
||||||
size_t totalSize = strlen("gneurshk") + sizeof(salt) + sizeof(nonce) + sizeof(encrypted);
|
size_t totalSize = strlen("gneurshk") + sizeof(salt) + sizeof(nonce) + encLen;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
unsigned char* outputBuffer = malloc(totalSize);
|
unsigned char* outputBuffer = malloc(totalSize);
|
||||||
if (outputBuffer == NULL) {
|
if (outputBuffer == NULL) {
|
||||||
@ -261,6 +262,12 @@ int decryptMessage(const char* inputFile, const char* outputFile, const char* pa
|
|||||||
|
|
||||||
size_t encLen = inLen - sizeof(salt) - sizeof(nonce) - 8;
|
size_t encLen = inLen - sizeof(salt) - sizeof(nonce) - 8;
|
||||||
|
|
||||||
|
if (inLen == 0) {
|
||||||
|
fprintf(stderr,ERR"File size is 0. No data.");
|
||||||
|
fclose(outFile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr,DBG"Size of encrypted file: %d bytes.\n",inLen);
|
fprintf(stderr,DBG"Size of encrypted file: %d bytes.\n",inLen);
|
||||||
fprintf(stderr,DBG"This means the encrypted content is %d bytes.\n",encLen);
|
fprintf(stderr,DBG"This means the encrypted content is %d bytes.\n",encLen);
|
||||||
|
|
||||||
@ -430,10 +437,13 @@ int main(int argc, char *argv[]) {
|
|||||||
char* password;
|
char* password;
|
||||||
|
|
||||||
// Set password and run!
|
// Set password and run!
|
||||||
if (pass == -1) {
|
if (pass > 0) {
|
||||||
password = getpass("Enter your encryption password: ");
|
|
||||||
} else {
|
|
||||||
password = argv[pass];
|
password = argv[pass];
|
||||||
|
} else if (in < 0) {
|
||||||
|
fprintf(stderr,ERR"Cannot read from stdin without a password.\n");
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
password = getpass("Enter your encryption password: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decrypt) {
|
if (decrypt) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user