Skip to content

Commit

Permalink
add helper tool to cause a segfault for testing purposes.
Browse files Browse the repository at this point in the history
`segfault-build` creates `segfault-run`. Running `segfault-run` results in
`segfault-run` terminating with a segfault. This is useful to test if
coredump files are being generated when an application crashes.

    sudo segfault-build

> /usr/sbin/segfault-build: SUCCESS. You can now run:
> segfault-run

    segfault-run

> Segmentation fault (core dumped)

    echo $?

> 139
  • Loading branch information
Patrick Schleizer committed Dec 25, 2020
1 parent e44067c commit f7b7457
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
16 changes: 16 additions & 0 deletions auto-generated-man-pages/segfault-build.8
@@ -0,0 +1,16 @@
.\" generated with Ronn-NG/v0.8.0
.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
.TH "SEGFAULT\-BUILD" "8" "January 2020" "debug-misc" "debug-misc Manual"
.SH "NAME"
\fBsegfault\-build\fR \- create segfault\-run program
.P
.SH "SYNOPSIS"
segfault\-build
.SH "DESCRIPTION"
Creates \fBsegfault\-run\fR\.
.SH "RETURN VALUES"
0 success\.
.P
Non\-zero otherwise\.
.SH "AUTHOR"
This man page has been written by Patrick Schleizer (adrelanos@riseup\.net)\.
7 changes: 7 additions & 0 deletions debian/control
Expand Up @@ -47,6 +47,13 @@ Description: Enables miscellaneous debug settings
passwords. Package `security-misc` disables coredumps. Package `debug-misc`
re-enables coredumps.
.
Contains a helper tool to cause a segfault for testing purposes.
`segfault-build` creates `segfault-run`. Running `segfault-run` results in
`segfault-run` terminating with a segfault. This is useful to test if
coredump files are being generated when an application crashes.
`/usr/sbin/segfault-build`
`/usr/share/debug-misc/segfault.c`
.
For better usability, to ease debugging in case of issues.
.
For better security, this package should only be installed on specific
Expand Down
3 changes: 3 additions & 0 deletions debian/rules
Expand Up @@ -8,5 +8,8 @@
%:
dh $@ --with=config-package

override_dh_installman:
dh_installman $(CURDIR)/auto-generated-man-pages/*

override_dh_installchangelogs:
dh_installchangelogs changelog.upstream upstream
25 changes: 25 additions & 0 deletions man/segfault-build.8.ronn
@@ -0,0 +1,25 @@
segfault-build(8) -- create segfault-run program
=============================================

<span class="comment">
# Copyright (C) 2012 - 2020 ENCRYPTED SUPPORT LP <adrelanos@riseup.net>
# See the file COPYING for copying conditions.
</span>

## SYNOPSIS

segfault-build

## DESCRIPTION

Creates `segfault-run`.

## RETURN VALUES

0 success.

Non-zero otherwise.

## AUTHOR

This man page has been written by Patrick Schleizer (adrelanos@riseup.net).
24 changes: 24 additions & 0 deletions usr/sbin/segfault-build
@@ -0,0 +1,24 @@
#!/bin/bash

## Copyright (C) 2020 - 2020 ENCRYPTED SUPPORT LP <adrelanos@riseup.net>
## See the file COPYING for copying conditions.

if [ ! "$(id -u)" = "0" ]; then
echo "$0: ERROR: Needs to run as root. Run:
sudo $0" >&2
exit 1
fi

if ! type -P gcc >/dev/null ; then
echo "$0: ERROR: gcc not installed. To install:
sudo apt update
sudo apt --no-install-recommends install gcc" >&2
exit 1
fi

gcc /usr/share/debug-misc/segfault.c -g -o /usr/bin/segfault-run

echo "$0: SUCCESS. You can now run:"
echo "segfault-run"
5 changes: 5 additions & 0 deletions usr/share/debug-misc/segfault.c
@@ -0,0 +1,5 @@
int main(void)
{
char *s = "hello world";
*s = 'H';
}

0 comments on commit f7b7457

Please sign in to comment.