Open chGoodchild opened 2 months ago
These are the fields that need to be changed:
option bssid 'F6:9F:C2:FA:75:A6'
option key 'coworking'
option encryption 'psk-mixed'
The fleet manager can also provide access to a static IP address from a VPN provider via nostr.
Commit: c64a37b3b83192bb201a4af4900091dffcb2bdc4
Multiple memory leaks when the note is large:
~/GLTollGate/nostr/c$ ./generate_encrypted_dm.sh "nostr_keys_router.json" "nostr_keys_operator.json" "test test test test test test test test test test test test test"
==115514== Memcheck, a memory error detector
==115514== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==115514== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==115514== Command: ./nostril --dm 34c83a1124c74c5236b7b2e8f45a0f6d00e7ce23eeb6a88607df8d9e7aae5670 --content test\ test\ test\ test\ test\ test\ test\ test\ test\ test\ test\ test\ test --sec b655fbb9270a50b10ed151ba080680502a6ead295421fc7b10a7787f389c0f14 --kind 14 --envelope --created-at 1724490403
==115514==
shared_secret 36e24f1021af26503c0572689b7bbda55f59ac566477d6968c717499b9bacf75
==115514== Invalid write of size 1
==115514== at 0x10A49F: cursor_push_byte (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10B83F: aes_encrypt (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10BF78: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x1099E3: main (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== Address 0x4bcc551 is 0 bytes after a block of size 65 alloc'd
==115514== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==115514== by 0x10BD43: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x1099E3: main (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==
==115514==
==115514== Invalid read of size 1
==115514== at 0x4852A10: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==115514== by 0x10E0D5: base64_encode_tail_using_maps (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10E200: base64_encode_using_maps (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10A857: base64_encode (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10BFE9: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x1099E3: main (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== Address 0x4bcc55e is 13 bytes after a block of size 65 alloc'd
==115514== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==115514== by 0x10BD43: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x1099E3: main (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==
["EVENT",{"id": "84b1f1567a656a4c2b1ff5490fc64c75e7930da9423f76ea6bc32e041aad5f40","pubkey": "a9f62ced51f3c06c24aa9aad2e01836421a90df04a6a9a735070efa2f77bec6f","created_at": 1724490403,"kind": 14,"tags": [["p","34c83a1124c74c5236b7b2e8f45a0f6d00e7ce23eeb6a88607df8d9e7aae5670"]],"content": "1AnDRj5Yu3hDrImuZ4dMmu1uBSLr/8w5wVd3PfK3SUe7f5rTl7lZ0IUk9CI2QPShpzo89uKkqF17OeEktF1k1YoL8X//W+2UIukjlT0cD3Q=?iv=RAv0ZGm0uR7GseCi+/7Z2A==","sig": "e17a5f853ad8dbcbaf11c7ff3e893e51f6b9bc31560542ce240c4d950073dfbcafb2e8a159b540924db76db3703525eca6647d232224d2589f60c9a9971e8f97"}]
["EVENT",{"id": "84b1f1567a656a4c2b1ff5490fc64c75e7930da9423f76ea6bc32e041aad5f40","pubkey": "a9f62ced51f3c06c24aa9aad2e01836421a90df04a6a9a735070efa2f77bec6f","created_at": 1724490403,"kind": 14,"tags": [["p","34c83a1124c74c5236b7b2e8f45a0f6d00e7ce23eeb6a88607df8d9e7aae5670"]],"content": "1AnDRj5Yu3hDrImuZ4dMmu1uBSLr/8w5wVd3PfK3SUe7f5rTl7lZ0IUk9CI2QPShpzo89uKkqF17OeEktF1k1YoL8X//W+2UIukjlT0cD3Q=?iv=RAv0ZGm0uR7GseCi+/7Z2A==","sig": "e17a5f853ad8dbcbaf11c7ff3e893e51f6b9bc31560542ce240c4d950073dfbcafb2e8a159b540924db76db3703525eca6647d232224d2589f60c9a9971e8f97"}]
==115514==
==115514== HEAP SUMMARY:
==115514== in use at exit: 103,626 bytes in 3 blocks
==115514== total heap usage: 4 allocs, 1 frees, 103,691 bytes allocated
==115514==
==115514== LEAK SUMMARY:
==115514== definitely lost: 103,626 bytes in 3 blocks
==115514== indirectly lost: 0 bytes in 0 blocks
==115514== possibly lost: 0 bytes in 0 blocks
==115514== still reachable: 0 bytes in 0 blocks
==115514== suppressed: 0 bytes in 0 blocks
==115514== Rerun with --leak-check=full to see details of leaked memory
==115514==
==115514== For lists of detected and suppressed errors, rerun with: -s
==115514== ERROR SUMMARY: 2242 errors from 60 contexts (suppressed: 0 from 0)
cursor_push_byte
:==115514== Invalid write of size 1
==115514== at 0x10A49F: cursor_push_byte (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10B83F: aes_encrypt (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10BF78: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
This indicates a buffer overflow in the cursor_push_byte
function, which is called during AES encryption.
base64_encode
:
==115514== Invalid read of size 1
==115514== at 0x4852A10: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==115514== by 0x10E0D5: base64_encode_tail_using_maps (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10E200: base64_encode_using_maps (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10A857: base64_encode (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== by 0x10BFE9: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
This shows that the base64_encode
function is reading beyond the allocated memory.
==115514== LEAK SUMMARY:
==115514== definitely lost: 103,626 bytes in 3 blocks
There are significant memory leaks in the program.
In make_encrypted_dm
:
Address 0x4bcc551 is 0 bytes after a block of size 65 alloc'd
Increase the buffer size, ensuring it's large enough for the encrypted content plus any padding.
[ ] In base64_encode
:
Ensure that the input buffer passed to this function is properly null-terminated.
Check if the output buffer is large enough for the encoded result.
[ ] For memory leaks:
Add proper memory deallocation (free) for all allocated memory.
Use tools like AddressSanitizer or careful code review to identify where memory is allocated but not freed.
[ ] In cursor_push_byte
:
Ensure that the cursor has enough space before writing. Add bounds checking.
[ ] General recommendations:
Implement better error handling and bounds checking throughout the code.
Use safer string handling functions (e.g., snprintf instead of sprintf).
Consider using C++ with RAII or smart pointers for better memory management.
Here's a potential fix for the make_encrypted_dm
function:
int make_encrypted_dm(secp256k1_context* ctx, struct key* key, struct nostr_event* ev, unsigned char nostr_pubkey[32], int kind)
{
// ... (existing code)
// Increase buffer size
size_t content_len = strlen(ev->content);
size_t padded_len = ((content_len + 15) / 16) * 16; // Round up to nearest 16 bytes
unsigned char* encbuf = (unsigned char*)malloc(padded_len + 16); // Add extra space for potential padding
if (!encbuf) {
fprintf(stderr, "make_encrypted_dm: Failed to allocate memory for encryption\n");
return 0;
}
// ... (perform encryption)
// Ensure base64 buffer is large enough
size_t base64_len = (padded_len + 2) / 3 * 4 + 1; // Base64 encoding length + null terminator
char* base64_output = (char*)malloc(base64_len);
if (!base64_output) {
fprintf(stderr, "make_encrypted_dm: Failed to allocate memory for base64 encoding\n");
free(encbuf);
return 0;
}
if (!base64_encode(encbuf, padded_len, base64_output, base64_len)) {
fprintf(stderr, "make_encrypted_dm: base64 encode of encrypted data failed\n");
free(encbuf);
free(base64_output);
return 0;
}
// ... (use base64_output)
free(encbuf);
free(base64_output);
return 1;
}
Remember to apply similar fixes to other parts of the code where buffer overflows or memory leaks are occurring. Always ensure that allocated memory is properly freed when no longer needed.
Config file or arguments for network name, gateway, gateway password, login password, nsec, npub, owner credentials etc...
Owner LNURL