Code Monkey home page Code Monkey logo

base64.c's Introduction

Metrics tetris.gif

base64.c's People

Contributors

joedf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

base64.c's Issues

ERROR: LeakSanitizer: detected memory leaks in test.c

memory leak detected

==34135==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 9 byte(s) in 1 object(s) allocated from:
#0 0x7f97d8fb7867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
https://github.com/elzoughby/Base64/pull/1 0x55c784089423 in test_b64_encodef /home/jason/Desktop/libbase64/test.c:169
https://github.com/elzoughby/Base64/issues/2 0x55c7840885d9 in main /home/jason/Desktop/libbase64/test.c:60
https://github.com/elzoughby/Base64/issues/3 0x7f97d8d04d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

SUMMARY: AddressSanitizer: 9 byte(s) leaked in 1 allocation(s)

the fix is to add a few calls to free

	
	FILE *pFile;
	pFile = fopen("B64_TEST01A.tmp","wb");
	if (pFile==NULL)
		return 0;
	
	int i, j=0;
	unsigned int test_a[] = HEXNUM_B;
	unsigned int size_a = NELEMS(test_a);
	
	for (i=0;i<size_a;i++) {
		fputc(test_a[i],pFile);
	}
	fclose(pFile);
	
	j = b64_encodef("B64_TEST01A.tmp","B64_TEST01B.tmp");
	remove("B64_TEST01A.tmp");
	
	if (!j)
		return 0;
	
	pFile = fopen("B64_TEST01B.tmp","rb");
	if (pFile==NULL)
		return 0;
	
	char *out = malloc(j+1);
	fgets(out,j+1,pFile);
	fclose(pFile);
	remove("B64_TEST01B.tmp");
	printf("\tComparing \"%s\" to \"%s\" : ",STRING_B,out);
	if (strcmp(STRING_B,out)==0)
	{
		free(out); //Add this line and the one below
		return 1;
	}
	
	free(out); //add this line too
	return 0;
}```

Cant compile

I cant compile that test.c file you gave. This is the error :
/tmp/cckwvSUl.o:hello.c:(.text+0x1b8): undefined reference to b64e_size' /tmp/cckwvSUl.o:hello.c:(.text+0x1c8): undefined reference to b64e_size'
/tmp/cckwvSUl.o:hello.c:(.text+0x1d8): undefined reference to b64e_size' /tmp/cckwvSUl.o:hello.c:(.text+0x227): undefined reference to b64_encode'
/tmp/cckwvSUl.o:hello.c:(.text+0x240): undefined reference to b64_encode' /tmp/cckwvSUl.o:hello.c:(.text+0x259): undefined reference to b64_encode'
/tmp/cckwvSUl.o:hello.c:(.text+0x3a7): undefined reference to b64d_size' /tmp/cckwvSUl.o:hello.c:(.text+0x3b4): undefined reference to b64d_size'
/tmp/cckwvSUl.o:hello.c:(.text+0x3c1): undefined reference to b64d_size' /tmp/cckwvSUl.o:hello.c:(.text+0x416): undefined reference to b64_decode'
/tmp/cckwvSUl.o:hello.c:(.text+0x42f): undefined reference to b64_decode' /tmp/cckwvSUl.o:hello.c:(.text+0x448): undefined reference to b64_decode'
/tmp/cckwvSUl.o:hello.c:(.text+0x636): undefined reference to b64_encodef' /tmp/cckwvSUl.o:hello.c:(.text+0x78b): undefined reference to b64_decodef'
collect2: error: ld returned 1 exit status

I am using kali linux mingw-gcc

Decode base64 to text crash

Decode result of "YWRtaW46ODgzNg==" should be "admin:8836"

When I do this
./b64f b YWRtaW46ODgzNg==

The test app crashes

sferreira@sferreira-PC:~/Downloads/base64.c-master/bin$ ./b64f b YWRtaW46ODgzNg==

DECODING from base64 to text
*** Error in `./b64f': free(): invalid next size (fast): 0x00000000010ac420 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f1e964b37e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f1e964bc37a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f1e964c053c]
./b64f[0x400ae5]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f1e9645c830]
./b64f[0x400749]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:01 7084656 /home/sferreira/Downloads/base64.c-master/bin/b64f
00601000-00602000 r--p 00001000 08:01 7084656 /home/sferreira/Downloads/base64.c-master/bin/b64f
00602000-00603000 rw-p 00002000 08:01 7084656 /home/sferreira/Downloads/base64.c-master/bin/b64f
010ac000-010cd000 rw-p 00000000 00:00 0 [heap]
7f1e90000000-7f1e90021000 rw-p 00000000 00:00 0
7f1e90021000-7f1e94000000 ---p 00000000 00:00 0
7f1e96226000-7f1e9623c000 r-xp 00000000 08:01 5509759 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f1e9623c000-7f1e9643b000 ---p 00016000 08:01 5509759 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f1e9643b000-7f1e9643c000 rw-p 00015000 08:01 5509759 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f1e9643c000-7f1e965fc000 r-xp 00000000 08:01 5509721 /lib/x86_64-linux-gnu/libc-2.23.so
7f1e965fc000-7f1e967fc000 ---p 001c0000 08:01 5509721 /lib/x86_64-linux-gnu/libc-2.23.so
7f1e967fc000-7f1e96800000 r--p 001c0000 08:01 5509721 /lib/x86_64-linux-gnu/libc-2.23.so
7f1e96800000-7f1e96802000 rw-p 001c4000 08:01 5509721 /lib/x86_64-linux-gnu/libc-2.23.so
7f1e96802000-7f1e96806000 rw-p 00000000 00:00 0
7f1e96806000-7f1e9682c000 r-xp 00000000 08:01 5509693 /lib/x86_64-linux-gnu/ld-2.23.so
7f1e96a0d000-7f1e96a10000 rw-p 00000000 00:00 0
7f1e96a2a000-7f1e96a2b000 rw-p 00000000 00:00 0
7f1e96a2b000-7f1e96a2c000 r--p 00025000 08:01 5509693 /lib/x86_64-linux-gnu/ld-2.23.so
7f1e96a2c000-7f1e96a2d000 rw-p 00026000 08:01 5509693 /lib/x86_64-linux-gnu/ld-2.23.so
7f1e96a2d000-7f1e96a2e000 rw-p 00000000 00:00 0
7ffe93345000-7ffe93366000 rw-p 00000000 00:00 0 [stack]
7ffe9338a000-7ffe9338d000 r--p 00000000 00:00 0 [vvar]
7ffe9338d000-7ffe9338f000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Decoded text from base64: aAborted (core dumped)

encode function crashes

Google directed me to this library, but when trying it it crashed immediately on the encode function.

unsigned int b64_encode(const unsigned int* in, unsigned int in_len, unsigned char* out) {

unsigned int i=0, j=0, k=0, s[3];

for (i=0;i<in_len;i++) {
    s[j++]=*(in+i);
    if (j==3) {
        out[k+0] = b64_chr[ s[0]>>2 ];

b64_chr[ s[0]>>2 ] crashes because s[0] is filled in with potentially a really high number (up to 2^30), and tries to dereference this inside b64_chr.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.