aes-everywhere
aes-everywhere copied to clipboard
Memory corruption with cpp on ubuntu 16.04 x64
Sorry for my english!
$ uname -a
Linux pt-ubuntu 4.15.0-66-generic #75~16.04.1-Ubuntu SMP Tue Oct 1 14:01:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ vi main.cpp
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#include "aes256.h"
#include <stdint.h>
using namespace std;
int main(int argc, char ** argv)
{
std::string text = std::string("Test string");
std::string passphrase = std::string("PASSPHRASE");
std::string encrypted = AES256::encrypt(text, passphrase);
std::string decrypted = AES256::decrypt(encrypted, passphrase);
cout << encrypted << endl;
cout << decrypted << endl;
return 0;
}
After multiple tries (~10): $ ./a.out
*** Error in `./a.out': malloc(): memory corruption (fast): 0x0000000001f09030 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f3a8cb877e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x82651)[0x7f3a8cb92651]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7f3a8cb94184]
./a.out[0x4041dc]
./a.out[0x4044b7]
./a.out[0x4046dc]
./a.out[0x404b72]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f3a8cb30830]
./a.out[0x4015c9]
======= Memory map: ========
00400000-00408000 r-xp 00000000 00:33 2494940 /home/peterpan/Downloads/aes-everywhere-master/cpp/build/a.out
00608000-00609000 r--p 00008000 00:33 2494940 /home/peterpan/Downloads/aes-everywhere-master/cpp/build/a.out
00609000-0060a000 rw-p 00009000 00:33 2494940 /home/peterpan/Downloads/aes-everywhere-master/cpp/build/a.out
01ef7000-01f29000 rw-p 00000000 00:00 0 [heap]
7f3a88000000-7f3a88021000 rw-p 00000000 00:00 0
7f3a88021000-7f3a8c000000 ---p 00000000 00:00 0
7f3a8c807000-7f3a8c90f000 r-xp 00000000 103:06 134432 /lib/x86_64-linux-gnu/libm-2.23.so
7f3a8c90f000-7f3a8cb0e000 ---p 00108000 103:06 134432 /lib/x86_64-linux-gnu/libm-2.23.so
7f3a8cb0e000-7f3a8cb0f000 r--p 00107000 103:06 134432 /lib/x86_64-linux-gnu/libm-2.23.so
7f3a8cb0f000-7f3a8cb10000 rw-p 00108000 103:06 134432 /lib/x86_64-linux-gnu/libm-2.23.so
7f3a8cb10000-7f3a8ccd0000 r-xp 00000000 103:06 134426 /lib/x86_64-linux-gnu/libc-2.23.so
7f3a8ccd0000-7f3a8ced0000 ---p 001c0000 103:06 134426 /lib/x86_64-linux-gnu/libc-2.23.so
7f3a8ced0000-7f3a8ced4000 r--p 001c0000 103:06 134426 /lib/x86_64-linux-gnu/libc-2.23.so
7f3a8ced4000-7f3a8ced6000 rw-p 001c4000 103:06 134426 /lib/x86_64-linux-gnu/libc-2.23.so
7f3a8ced6000-7f3a8ceda000 rw-p 00000000 00:00 0
7f3a8ceda000-7f3a8cef0000 r-xp 00000000 103:06 136492 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f3a8cef0000-7f3a8d0ef000 ---p 00016000 103:06 136492 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f3a8d0ef000-7f3a8d0f0000 rw-p 00015000 103:06 136492 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f3a8d0f0000-7f3a8d262000 r-xp 00000000 103:06 1181328 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f3a8d262000-7f3a8d462000 ---p 00172000 103:06 1181328 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f3a8d462000-7f3a8d46c000 r--p 00172000 103:06 1181328 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f3a8d46c000-7f3a8d46e000 rw-p 0017c000 103:06 1181328 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f3a8d46e000-7f3a8d472000 rw-p 00000000 00:00 0
7f3a8d472000-7f3a8d498000 r-xp 00000000 103:06 133461 /lib/x86_64-linux-gnu/ld-2.23.so
7f3a8d66a000-7f3a8d670000 rw-p 00000000 00:00 0
7f3a8d696000-7f3a8d697000 rw-p 00000000 00:00 0
7f3a8d697000-7f3a8d698000 r--p 00025000 103:06 133461 /lib/x86_64-linux-gnu/ld-2.23.so
7f3a8d698000-7f3a8d699000 rw-p 00026000 103:06 133461 /lib/x86_64-linux-gnu/ld-2.23.so
7f3a8d699000-7f3a8d69a000 rw-p 00000000 00:00 0
7ffcd8cbd000-7ffcd8cde000 rw-p 00000000 00:00 0 [stack]
7ffcd8d27000-7ffcd8d2a000 r--p 00000000 00:00 0 [vvar]
7ffcd8d2a000-7ffcd8d2c000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted (core dumped)
Cpp implementation have some bugs. It sometimes works and sometimes not, I tried to fix that, but I still can't. I think I need full rewrite this implementation, so you should not to use it for now.