Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
View .vimrc
" vim > vi
set nocompatible
syntax on
filetype on
filetype plugin on
filetype indent on
" auto reload changes files (that don't have unsaved changes)
set autoread
@bnoordhuis
bnoordhuis / await.js
Created Aug 28, 2019
Await pending promises on Node.js process exit
View await.js
// Copyright (c) 2019, Ben Noordhuis <info@bnoordhuis.nl>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@bnoordhuis
bnoordhuis / bytestokey.js
Created Nov 29, 2017
Compute key+IV from passphrase (createCipher to createCipheriv migration script)
View bytestokey.js
// Copyright (c) 2017, Ben Noordhuis <info@bnoordhuis.nl>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@bnoordhuis
bnoordhuis / fno_delete_null_pointer_checks.diff
Created Sep 20, 2016
clang 3.9.0 -fno-delete-null-pointer-checks
View fno_delete_null_pointer_checks.diff
diff --git a/tools/clang/include/clang/Driver/Options.td b/tools/clang/include/clang/Driver/Options.td
index d03ab04..0e03a0a 100644
--- a/tools/clang/include/clang/Driver/Options.td
+++ b/tools/clang/include/clang/Driver/Options.td
@@ -479,6 +479,12 @@ def fno_autolink : Flag <["-"], "fno-autolink">, Group<f_Group>,
Flags<[DriverOption, CC1Option]>,
HelpText<"Disable generation of linker directives for automatic library linking">;
+def fdelete_null_pointer_checks : Flag<["-"], "fdelete-null-pointer-checks">,
+ Group<f_Group>, Flags<[CC1Option]>,
@bnoordhuis
bnoordhuis / uml-notes.md
Last active Oct 11, 2018
Setting up User Mode Linux on Fedora 20
View uml-notes.md

user mode linux: build and run

Generate default .config.

$ make defconfig ARCH=um SUBARCH=x86_64

Build the linux ELF binary.

$ make -j8 linux ARCH=um SUBARCH=x86_64
View issue1180.cc
// scons mode=debug arch=x64
// g++ -m64 -Wall -ggdb stack-guard.cc -Iinclude libv8_g.a -lpthread && ./a.out; echo "$?"
//
// gcc version 4.4.5 (Debian 4.4.5-8)
// http://v8.googlecode.com/svn/trunk@r6858
//
// Repros on x64, does not repro in ia32
#include "v8.h"
#include <iostream>
#include <assert.h>
@bnoordhuis
bnoordhuis / un.c
Created Feb 8, 2014
PoC of OS X sockaddr_un system crash
View un.c
// Crashes OS X 10.8, `cc un.c && while :; do ./a.out ; done` to run.
// The buffer overflow usually gets triggered within the first three
// or four runs. Make sure you back up your data first!
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
View fib.js
// Copyright (c) 2014, Ben Noordhuis <info@bnoordhuis.nl>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@bnoordhuis
bnoordhuis / container_of.rs
Created Jan 26, 2014
container_of() in Rust. Look up address of embedding struct.
View container_of.rs
// Copyright (c) 2014, Ben Noordhuis <info@bnoordhuis.nl>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@bnoordhuis
bnoordhuis / gccbug.c
Created May 19, 2013
gcc + asm + on-stack iovec = uninitialized memory
View gccbug.c
// Compile at -O0 and -O1 or higher and compare the output of
// `strace -e pwritev a.out`. At -O0:
//
// pwritev(1, [{"Hello ", 6}, {"world!", 6}, {"\n", 1}], 3, 0) = -1 ESPIPE
// (Illegal seek)
//
// At -O1 or higher:
//
// pwritev(1, [{"", 0}, {"H\211l$\330L\211d$\340H\215-\367\10 \0L\215%\350\10
// \0H\211\\$\320L\211l"..., 4195360}, {"", 0}], 3, 0) = -1 ESPIPE (Illegal
You can’t perform that action at this time.