Skip to content

Instantly share code, notes, and snippets.

View FauxFaux's full-sized avatar

Chris West FauxFaux

View GitHub Profile
@FauxFaux
FauxFaux / custom_error.rs
Created May 21, 2017 15:30
Creating and detecting a custom error type (~ `e instanceof Fooexception`)
use std::error;
use std::fmt;
use std::io;
#[derive(Debug)]
struct MyError {
}
impl error::Error for MyError {
fn description(&self) -> &str {
@FauxFaux
FauxFaux / mmap_sigbus.c
Created April 12, 2017 23:43
Repairing a SIGBUS from an OOB read of an mmap'd file
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
// cc drop-privs-harder.c -o drop-privs-harder -lseccomp
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/prctl.h>
#include <errno.h>
#include <seccomp.h>
printf "[Service]\nSystemCallFilter=~fsync sync syncfs fdatasync msync sync_file_range\nSystemCallErrorNumber=0\n" \
| s env EDITOR='tee -a' systemctl edit [email protected]
@FauxFaux
FauxFaux / find_deleted_files.py
Created November 14, 2016 14:48
checkrestart / psdel reimplementation
#!/usr/bin/python3
# inspired by psdel, referenced from the checkrestart (debian-goodies) source code
import collections
import errno
import glob
import os
import re
import stat
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
static const int supported_bits = 32;
@FauxFaux
FauxFaux / do-release-upgrade.md
Last active May 13, 2023 20:43
What does Ubuntu's do-release-upgrade script actually do?

Ubuntu encourage upgrading between releases by running a command, instead of by manually editing sources and getting on with it. This tool's name is do-release-upgrade, and I believe it should just be doing:

sed -i 's/wily/xenial/g' /etc/apt/sources.list /etc/apt/sources.list.d/*

This command does not explain what it wants to do, or why it is doing anything. It has, in the past:

  • Disabled repos I was using, and hence broken the software in them.
@FauxFaux
FauxFaux / chrome2ca.sh
Created December 30, 2015 00:18
Capture CAs from Chrome history
locate -r '/History$' | fgrep chrom | while read x; do echo select url from urls\; | sqlite3 "$x"; done > hist
cut -d/ -f 3 hist | sort -u | xargs -P200 -I{} -n1 -- sh -c ': | openssl s_client -connect {}:443 2> {}.path > {}.handshake'
for f in *.path; do if ! fgrep 'verify erro' $f >/dev/null; then grep -m1 '^depth' $f; fi; done | cut -d' ' -f 2- | sort | uniq -c | sort -n
for f in *.path; do if ! fgrep 'verify erro' $f >/dev/null; then grep -m1 '^depth' $f; fi; done | cut -d' ' -f 2- | sed 's/.*O = //;s/, OU =.*//;s/, CN = //;s/The //;s/[",.]//g;s/ Inc//' | sort | uniq -c | sort -n
javascript:t=document.getElementsByTagName("*");for(var i=0;i<t.length;++i){var a=t[i];var c=window.getComputedStyle(a);if(c.position&&c.position=="fixed"){a.parentNode.removeChild(a);}};
sta() { s service unbound start 2>/dev/null >/dev/null && echo started }
sto() { s service unbound stop >/dev/null && echo stopped }
ki() { s killall unbound >/dev/null && echo killed }
te() { dig +dnssec example.com @localhost | fgrep HEADER }
ki; sta; te; te; sto; sta; te; te; sto; sta; te; ki; sta; te; te
killed
started
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51393
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40128