Commit 6187e3ef authored by Natanael Copa's avatar Natanael Copa

main/fortify-headers: fix realpath()

ref #4075
parent 645da2ae
From 31d62b60c5b4f1baa795537da898a83e39be9dd1 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Thu, 7 May 2015 14:41:36 +0200
Subject: [PATCH fortify-headers] fix realpath when stdlib.h is included before
limits.h
To: sin@2f30.org
If program includes stdlib.h before limits.h without _XOPEN_SOURCE,
_GNU_SOURCE or _BSD_SOURCE explicitly set, then will it always trigger
the trap with musl libc.
This is becase stdlib.h will pull in features.h which will set
_GNU_SOURCE. This means that the fortify stdlib.h will not include
limits.h but it will still trigger the fortified realpath(), but without
PATH_MAX set.
We fix this by including system stdlib.h before testing if limits.h
should be included.
Since PATH_MAX is known at compile time we can also error at compile
time, instead of compiling a broken realpath().
---
include/stdlib.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/stdlib.h b/include/stdlib.h
index 22f1f2b..6629652 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -1,12 +1,12 @@
#ifndef _FORTIFY_STDLIB_H
#define _FORTIFY_STDLIB_H
+#include_next <stdlib.h>
+
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#include_next <limits.h>
#endif
-#include_next <stdlib.h>
-
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
#ifdef __cplusplus
@@ -23,7 +23,7 @@ char *realpath(const char *path, char *resolved)
if (resolved) {
#ifndef PATH_MAX
- __builtin_trap();
+# error PATH_MAX unset. A fortified realpath will not work.
#else
bos = __builtin_object_size(resolved, 0);
if (PATH_MAX > bos)
--
2.4.0
......@@ -2,7 +2,7 @@
# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=fortify-headers
pkgver=0.4
pkgrel=0
pkgrel=1
pkgdesc="standalone fortify source implementation"
url="http://git.2f30.org/fortify-headers/"
arch="noarch"
......@@ -13,6 +13,7 @@ makedepends="$depends_dev"
install=""
subpackages=""
source="http://dl.2f30.org/releases/$pkgname-$pkgver.tar.gz
0001-fix-realpath-when-stdlib.h-is-included-before-limits.patch
"
_builddir="$srcdir"/$pkgname-$pkgver
......@@ -36,6 +37,9 @@ package() {
rm -f "$pkgdir"/usr/lib/*.la
}
md5sums="99b34bbd925cbfe383252fe107cafece fortify-headers-0.4.tar.gz"
sha256sums="fedfbd951bf4d4bd30d32bef20710d6124c004037df52059a274c090c1f11a0a fortify-headers-0.4.tar.gz"
sha512sums="669bf35df5278d4557caa2c8f28e33fe3e4a03c4267eed2cc8638dcb8e705d8797e487fbb524d9ff919e2752f1dc817cef9d41f14ceb46d520661e3d2301c5f2 fortify-headers-0.4.tar.gz"
md5sums="99b34bbd925cbfe383252fe107cafece fortify-headers-0.4.tar.gz
47e6831fc0fa84075f5750b47b13d888 0001-fix-realpath-when-stdlib.h-is-included-before-limits.patch"
sha256sums="fedfbd951bf4d4bd30d32bef20710d6124c004037df52059a274c090c1f11a0a fortify-headers-0.4.tar.gz
1216858e96afa30b093ec420d0b6d8943036d8816f54a59e3fa6ef5b5b0ee32e 0001-fix-realpath-when-stdlib.h-is-included-before-limits.patch"
sha512sums="669bf35df5278d4557caa2c8f28e33fe3e4a03c4267eed2cc8638dcb8e705d8797e487fbb524d9ff919e2752f1dc817cef9d41f14ceb46d520661e3d2301c5f2 fortify-headers-0.4.tar.gz
5364518842709e2c25baaf9a8b7651db422f2d37c64fac690f671daa157214192933ac1821a29d31d8ddfd49dd8e2625e3dfbe6fdba3b2b899c533f0f73e4699 0001-fix-realpath-when-stdlib.h-is-included-before-limits.patch"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment