Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@JustonDavies
JustonDavies / json_tests.c
Created September 25, 2013 15:35
C string realloc and concat
char * strautocat(char **buffer, const char *str1) //char **buffer, const char *format, vargs? Ive done this before
{
assert(str1 != NULL); assert(buffer != NULL);
if(*buffer == NULL){*buffer = (char *)calloc(sizeof(char)*DEFAULT_STRING_LENGTH,sizeof(char));}
size_t allocated_size, required_size;
allocated_size = malloc_usable_size(*buffer);
required_size = strlen(str1)+strlen(*buffer)+1;
while(required_size > allocated_size)
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zmq.h>
#define zcheck_err(eval, condition, fmt, args...) \
((void)({ \
errno = 0; \
if (!(condition)) { \
==31223== Memcheck, a memory error detector
==31223== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==31223== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==31223== Command: out/nexus
==31223==
ZMQ version is 3.2.3
CZMQ version is 3.4.0
Starting Thread...
^CInterrupted, sending kill signal...
Shutting down...
@JustonDavies
JustonDavies / all_in_one.c
Last active December 15, 2015 13:18
Potential attack vector for exposed ZeroMQ services
#include <stdio.h>
#include <czmq.h>
#define URI "tcp://127.0.0.1:5056"
int
main(int argc, const char* argv[]) {
int count, rc;
char buff[256];
@JustonDavies
JustonDavies / main.c
Last active December 15, 2015 13:09
CZMQ zloop under zthread memory leak example code.
#include <stdio.h>
#include <czmq.h>
int start_thread(void *args) {
printf ("Starting Thread...\n");
void * ctx = zctx_new ();
assert (ctx);
zloop_t *reactor = zloop_new ();
//-- Comment or uncomment this line to toggle the 'valgrind --leak-check=full' errors ----------------------------------