Skip to content

Instantly share code, notes, and snippets.

View bnoordhuis's full-sized avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
@bnoordhuis
bnoordhuis / count-promises.js
Created September 28, 2023 19:13
[node.js] count active promises via the V8 inspector
"use strict"
const inspector = require("node:inspector/promises")
const session = new inspector.Session()
session.connect()
countPromises(session).then(console.log)
async function countPromises(session) {
// resource management: put all results in an object group
const objectGroup = crypto.randomUUID()
@bnoordhuis
bnoordhuis / README.md
Created May 14, 2022 21:04
How to fix: unable to install (supposed) new info file /var/lib/dpkg/tmp.ci: Operation not permitted

A system crash at an inopportune time left my file system in a corrupted state. Fixing it up with fsck(1) worked just fine but made a subsequent system upgrade fail with an unusual error:

dpkg: error processing /var/cache/apt/archives/libfoo-1.2.3_amd64.deb (--unpack):
unable to install (supposed) new info file `/var/lib/dpkg/tmp.ci/symbols': Operation not permitted

The directory /var/lib/dpkg/tmp.ci did not exist. Creating it manually and re-running the upgrade failed exactly the same way (and removed the directory again.)

@bnoordhuis
bnoordhuis / .vimrc
Created July 21, 2020 11:01
.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 August 28, 2019 21:47
Await pending promises on Node.js process exit
// 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 November 29, 2017 22:55
Compute key+IV from passphrase (createCipher to createCipheriv migration script)
// 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 September 20, 2016 18:14
clang 3.9.0 -fno-delete-null-pointer-checks
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 December 10, 2022 21:32
Setting up User Mode Linux on Fedora 20

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
// 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 February 8, 2014 12:01
PoC of OS X sockaddr_un system crash
// 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>
// 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