Skip to content

Instantly share code, notes, and snippets.

View jonathanmarvens's full-sized avatar

Jonathan Barronville jonathanmarvens

View GitHub Profile
@jonathanmarvens
jonathanmarvens / pointer-long-fun.c
Created April 21, 2014 15:56
A pointer example I used to show a mentee that pointers are pretty much just integers with memory addresses as values.
#include <stdio.h>
int
main(void)
{
long a = 1;
long * b = &a;
long c = (long) b;
printf("c: %ld\n", c);
#define CHECK_BIT(val, position) ((val) & (1 << (position)))
#define CHECK_BIT_TRUTH_VAL(val, position) (!! CHECK_BIT(val, position))

In the general sense, a VALUE is just a C pointer to a Ruby object data type. We use VALUEs in the C code like we would use objects in the Ruby code.

some_function(VALUE arg_object)
{
  some_method(arg_object);
}

One would expect that the VALUE is just a typedef to a C pointer and there’s a lookup table as to which object it represents, and this would be partially correct. However, there’s also some trickery involved.

#!/usr/bin/env python2
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
#!/usr/bin/python
# Connects to servers vulnerable to CVE-2014-0160 and looks for cookies, specifically user sessions.
# Michael Davis ([email protected])
# Based almost entirely on the quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import select

So apparently MRI brings along its own statically linked OpenSSL:

$ openssl version
OpenSSL 0.9.8y 5 Feb 2013

$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin12.0]

$ ruby -r openssl -e 'puts OpenSSL::OPENSSL_VERSION'
function extend() {
var consumer = arguments[0];
var providers = ([]).slice.call(arguments, 1);
for (var a = 0; a < providers.length; a++) {
var provider = providers[a];
var except = (provider['except'] || []);
except.push('except');
###########################################
# Copyright (c) 2014 Jonathan Barronville #
# License: MIT. #
###########################################
function fish_prompt
set last_command_status $status
echo ''
git diff --ignore-submodules --quiet HEAD
git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||'