Add new realpath patch

This commit is contained in:
topjohnwu 2022-03-22 04:14:21 -07:00
parent 49136e1127
commit 92c1537f51
37 changed files with 329 additions and 76 deletions

View File

@ -6,7 +6,7 @@ LOCAL_MODULE := busybox
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES := libselinux
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
LOCAL_LDFLAGS := -static
LOCAL_LDFLAGS := -static -Wl,--wrap=realpath
LOCAL_CFLAGS := \
-w -include include/autoconf.h -D__USE_BSD -D__USE_GNU \
-DBB_VER=\"$(BB_VER)\" -DBB_BT=AUTOCONF_TIMESTAMP

View File

@ -1,7 +1,7 @@
From c9fbf480bdca1c8c8d64e809a8fd548a2e38870a Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Fri, 27 Nov 2015 11:40:52 -0400
Subject: [PATCH 01/35] Fix mconf/lkc host "warning statement with no effect"
Subject: [PATCH 01/36] Fix mconf/lkc host "warning statement with no effect"
---
scripts/kconfig/lkc.h | 4 ++--
@ -23,5 +23,5 @@ index 527f60c99..1972cb9a0 100644
#ifdef __cplusplus
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From a1fb60cf04de4f8f95ada00c09ab5f74e016e3dd Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Tue, 4 May 2021 00:56:55 -0300
Subject: [PATCH 02/35] android: fix 'mount', 'umount', 'fsck', 'df'
Subject: [PATCH 02/36] android: fix 'mount', 'umount', 'fsck', 'df'
Patch by Tias Guns <tias@ulyssis.org>, based on 'Bionic Patch V1.0' by Vitaly Greck
https://code.google.com/p/busybox-android/downloads/detail?name=patch
@ -321,5 +321,5 @@ index 000000000..107748740
+ return NULL;
+}
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 657c71ad7841c8d1399fdd523c965fa4bb849b2e Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Thu, 3 Dec 2015 17:01:57 -0400
Subject: [PATCH 03/35] eject: add missing headers
Subject: [PATCH 03/36] eject: add missing headers
Imported from dorimanx's combined ported header toolchain:
https://github.com/dorimanx/android-busybox-ndk
@ -526,5 +526,5 @@ index 000000000..767945236
+
+#endif /* scsi/sg.h */
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 8fbbf922b761d901768bc752bf0f1b05283fd659 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Tue, 10 Jan 2017 10:24:29 -0400
Subject: [PATCH 04/35] fix udhcpd and nameif, add ether_ntoa_r and
Subject: [PATCH 04/36] fix udhcpd and nameif, add ether_ntoa_r and
ether_aton_r from glibc
this patch also fixes part of arping and ether-wake, but not sufficiently yet
@ -249,5 +249,5 @@ index 91f70970a..732c0bcfa 100644
#include "dhcpc.h"
#include "dhcpd.h"
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 640579c63ab00f44a41dd8e5692bc1301a600853 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Wed, 2 Dec 2015 23:44:06 -0400
Subject: [PATCH 05/35] fix ether-wake, avoid ether_hostton and include
Subject: [PATCH 05/36] fix ether-wake, avoid ether_hostton and include
if_ether
Patch by Tias Guns <tias@ulyssis.org>, based on 'no-ether_hostton' by Dan Drown
@ -34,5 +34,5 @@ index 809c0d9f0..920f0c4a0 100644
bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa_r(eaddr, ether_buf));
#endif
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 40cd1220200b93f9db133d0cd68f1cd054c1473c Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Thu, 3 Dec 2015 01:29:35 -0400
Subject: [PATCH 06/35] loadfont/setfont/conspy: add missing header
Subject: [PATCH 06/36] loadfont/setfont/conspy: add missing header
Imported from dorimanx's combined ported header toolchain:
https://github.com/dorimanx/android-busybox-ndk
@ -51,5 +51,5 @@ index 000000000..8b8e56d4d
+
+#endif /* sys/kd.h */
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 2148257822c6b74e77274be6ad436c753187b8b4 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Mon, 12 Sep 2016 14:45:35 -0300
Subject: [PATCH 07/35] android syscalls: shmget/msgget/semget
Subject: [PATCH 07/36] android syscalls: shmget/msgget/semget
Patch modified by Tias Guns <tias@ulyssis.org> from 'no-sys-shm,msg,sem' by Dan Drown
http://dan.drown.org/android/src/busybox/
@ -37,5 +37,5 @@ index dc40d9155..82b600ced 100644
int tcdrain(int fd)
{
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 9eb6343f23bc887b33a049f172060760edbd0fa7 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Mon, 12 Sep 2016 14:46:40 -0300
Subject: [PATCH 08/35] android syscalls: msgctl shmctl
Subject: [PATCH 08/36] android syscalls: msgctl shmctl
Patch by Tias Guns <tias@ulyssis.org>
Rebased for busybox 1.25.0 by Chris Renshaw <osm0sis@outlook.com>
@ -34,5 +34,5 @@ index 82b600ced..018f72d62 100644
int tcdrain(int fd)
{
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 89683c3fdcc92305d2eb23623e0a4f5a1ead1e9c Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Mon, 12 Sep 2016 14:48:30 -0300
Subject: [PATCH 09/35] android syscalls: shmdt shmat sembuf
Subject: [PATCH 09/36] android syscalls: shmdt shmat sembuf
Patch by Tias Guns <tias@ulyssis.org>
Rebased for busybox 1.25.0 by Chris Renshaw <osm0sis@outlook.com>
@ -44,5 +44,5 @@ index 018f72d62..b5ea2612e 100644
int tcdrain(int fd)
{
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 02535ff6c29017a2f314122ff819c4b8886d02c6 Mon Sep 17 00:00:00 2001
From: Tias Guns <tias@ulyssis.org>
Date: Sun, 5 Aug 2012 15:25:34 +0200
Subject: [PATCH 10/35] android syscall (non-trivial): semctl
Subject: [PATCH 10/36] android syscall (non-trivial): semctl
needed by ipcs and ipcrm, also needed (but not sufficient) for syslogd and logread
@ -80,5 +80,5 @@ index 000000000..2c600e4f0
+ return syscall(__NR_semctl, semid, semnum, cmd, arg);
+}
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From f13b59490de357e8cf526ba3bd1c3511bb29a409 Mon Sep 17 00:00:00 2001
From: Umakanthan Chandran <cumakt@gmail.com>
Date: Fri, 3 Mar 2017 07:32:22 +0530
Subject: [PATCH 11/35] missing_syscalls/semctl: fix missing definitions on x86
Subject: [PATCH 11/36] missing_syscalls/semctl: fix missing definitions on x86
and MIPS NDK cross-compiles
Signed-off-by: Umakanthan Chandran <cumakt@gmail.com>
@ -81,5 +81,5 @@ index 2c600e4f0..84ab1c92e 100644
int semctl(int semid, int semnum, int cmd, ...) {
union semun arg;
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 8128d92f56396a819225d1d802956de29bc65bff Mon Sep 17 00:00:00 2001
From: Tias Guns <tias@ulyssis.org>
Date: Tue, 20 Mar 2012 21:26:07 +0000
Subject: [PATCH 12/35] fix ipcs, ipcrm no sys/sem-shm-msg, etc
Subject: [PATCH 12/36] fix ipcs, ipcrm no sys/sem-shm-msg, etc
patch from 'no-sys-shm,msg,sem' by Dan Drown
http://dan.drown.org/android/src/busybox/
@ -41,5 +41,5 @@ index ef2529c05..3a08020e8 100644
#else
/* according to X/OPEN we have to define it ourselves */
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From bc154ac766f31b242e82cb6b9478abb024881e9c Mon Sep 17 00:00:00 2001
From: Tias Guns <tias@ulyssis.org>
Date: Tue, 20 Mar 2012 21:30:10 +0000
Subject: [PATCH 13/35] fix syslogd, logread: add syslog.h, semop shmdt-at
Subject: [PATCH 13/36] fix syslogd, logread: add syslog.h, semop shmdt-at
patch from 'no-sys-shm,msg,sem' and 'sys-syslog' by Dan Drown
"sys/syslog.h header for syslogd"
@ -169,5 +169,5 @@ index 94d8273b6..9a768daa5 100644
#if 0
/* For the record: with SYSLOG_NAMES <syslog.h> defines
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From d5018f13db3b01797245f0f163bd3b48d6bc26a3 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Sun, 18 Feb 2018 07:54:58 -0400
Subject: [PATCH 14/35] fix fsck.minix, mkfs.minix: undef HAVE_SETBIT,
Subject: [PATCH 14/36] fix fsck.minix, mkfs.minix: undef HAVE_SETBIT,
MINIX2_SUPER_MAGIC, MINIX2_SUPER_MAGIC
"there is no setbit/clrbit in bionic"
@ -43,5 +43,5 @@ index 83ffe6da5..91ced691c 100644
BLOCK_SIZE = 1024,
BITS_PER_BLOCK = BLOCK_SIZE << 3,
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From da4ee617840f197c402b00d30954fbb19a5d0fe3 Mon Sep 17 00:00:00 2001
From: Tias Guns <tias@ulyssis.org>
Date: Mon, 19 Mar 2012 18:24:29 +0000
Subject: [PATCH 15/35] fix ipv6, add ipv6_route.h
Subject: [PATCH 15/36] fix ipv6, add ipv6_route.h
from 'in6_rtmsg' by Dan Drown
"in6_rtmsg defined in linux/ipv6_route.h"
@ -110,5 +110,5 @@ index ff5daa8a7..89617db9d 100644
#include "libbb.h"
#include "inet_common.h"
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 33f7280a5cd1ce160a2239be320601888292f95f Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Thu, 6 May 2021 16:09:06 -0300
Subject: [PATCH 16/35] additional fix-up for IPV6 on Android API 21+
Subject: [PATCH 16/36] additional fix-up for IPV6 on Android API 21+
fixes: networking/interface.c:62:8: error: redefinition of 'struct in6_ifreq'
@ -50,5 +50,5 @@ index 89617db9d..f20070889 100644
#include <linux/ipv6_route.h>
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 9fe432ccdd315f78da7d6532e2492394231b7059 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Wed, 19 Jul 2017 17:22:55 -0300
Subject: [PATCH 17/35] fix udhcpc6: add missing ifaddrs.h and
Subject: [PATCH 17/36] fix udhcpc6: add missing ifaddrs.h and
getifaddrs/freeifaddrs functions
ifaddrs implementation from 'android-ifaddrs' by Kenneth MacKay:
@ -707,5 +707,5 @@ index 000000000..9cd19fec1
+
+#endif
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 0da392210ffdf897f9dfbc7ca235b9d2784af466 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Sat, 2 Oct 2021 01:11:12 -0300
Subject: [PATCH 18/35] fix hush: add missing definitions on Android API 21+
Subject: [PATCH 18/36] fix hush: add missing definitions on Android API 21+
platform FAST_FUNC adjustment to support NDK unified headers by John Wu <topjohnwu@gmail.com>
@ -70,5 +70,5 @@ index 7913353e2..b652a2112 100644
+}
+#endif
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From b0fa1f42f97cdfe4688d8f3a4936de7202cb0534 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Tue, 10 Jan 2017 10:49:59 -0400
Subject: [PATCH 19/35] fix hush, add glob and sigisemptyset
Subject: [PATCH 19/36] fix hush, add glob and sigisemptyset
Patch by Tias Guns <tias@ulyssis.org>, based on 'glob' by Dan Drown
http://dan.drown.org/android/src/busybox/
@ -963,5 +963,5 @@ index 000000000..82973138e
+ return set;
+}
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From f6519d3325f39ffeaa94222821c33f939c81ad65 Mon Sep 17 00:00:00 2001
From: John Wu <topjohnwu@gmail.com>
Date: Sun, 12 Aug 2018 18:31:26 +0800
Subject: [PATCH 20/35] glob: minor adjustments to support unified headers
Subject: [PATCH 20/36] glob: minor adjustments to support unified headers
---
shell/glob.h | 6 +++---
@ -39,5 +39,5 @@ index e8e65786d..c274a8f6a 100644
#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From bf6a4c512499e7df05228a895690f599a0fd8f28 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Thu, 6 May 2021 16:30:26 -0300
Subject: [PATCH 21/35] modinfo/modprobe: use ifdef block for android
Subject: [PATCH 21/36] modinfo/modprobe: use ifdef block for android
without-utsrel modules path
and fixes the modules.dep requirement, it is now optional...
@ -149,5 +149,5 @@ index 235706fd5..4f4ee11e1 100644
if (opt & OPT_LIST_ONLY) {
int i;
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From b8f5ac4fa5179fba6b9af14a0ab7bfd3dc35a42f Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Mon, 12 Sep 2016 16:55:01 -0300
Subject: [PATCH 22/35] depmod: fix syntax with modules in parameter
Subject: [PATCH 22/36] depmod: fix syntax with modules in parameter
Patch by Tanguy Pruvot <tanguy.pruvot@gmail.com>
Change-Id: I21b8664db01cf0132db82f8d6caa1a0e77e71004
@ -28,5 +28,5 @@ index bb42bbefe..5e4c4c538 100644
for (ptr = image; ptr < image + len - 10; ptr++) {
if (is_prefixed_with(ptr, "depends=")) {
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 0e0d4777bd7e047e6e4f7e441c8012477ca41fa1 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Mon, 26 Jun 2017 23:53:06 -0300
Subject: [PATCH 23/35] fix reboot+poweroff: hack android_reboot support
Subject: [PATCH 23/36] fix reboot+poweroff: hack android_reboot support
based on 'reboot.c' and 'halt.c' patches from CyanogenMod:
https://github.com/CyanogenMod/android_external_busybox/commit/8aeb3719294721f744239ced474d159f073eef55#diff-51036c2b1c4282b63402a0e0286a066a
@ -104,5 +104,5 @@ index 000000000..97fe523a7
+ return ret;
+}
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 608f5da2ca492898cfae4f982f5d420ac8cdb75c Mon Sep 17 00:00:00 2001
From: osm0sis <osm0sis@outlook.com>
Date: Thu, 20 Jul 2017 09:16:07 -0300
Subject: [PATCH 24/35] fix tls: avoid problematic ASM code only triggered by
Subject: [PATCH 24/36] fix tls: avoid problematic ASM code only triggered by
x86 NDK builds
https://bugs.busybox.net/show_bug.cgi?id=13716#c7
@ -23,5 +23,5 @@ index 215e92b02..1cd351f4a 100644
# define PSTM_32BIT
# define PSTM_X86
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 052f60d1708392714a6b5d2db27be44f69eefdfa Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Sat, 21 Jul 2018 20:02:13 -0300
Subject: [PATCH 25/35] fix nslookup, add libres, a dietlibc resolver
Subject: [PATCH 25/36] fix nslookup, add libres, a dietlibc resolver
Using bionic's resolver functions does not allow changing the dns
server. Use dietlibc's resolver code instead (see package libres-devel)
@ -1241,5 +1241,5 @@ index de7b5c0e7..1de598505 100644
/* (but it also says "may be enabled in /etc/resolv.conf") */
/*_res.options |= RES_USE_INET6;*/
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From d8270cbc21e248803c0479771986042c416a2c93 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Wed, 30 Oct 2019 02:47:24 -0300
Subject: [PATCH 26/35] hack: use dietlibc's resolver to avoid static
Subject: [PATCH 26/36] hack: use dietlibc's resolver to avoid static
compiliation issues with bionic's getaddrinfo() returning only null instead
of opening the expected connection to /dev/socket/dnsproxyd
@ -41,5 +41,5 @@ index 5dd9cfd28..ecfcdaefa 100644
}
#if !ENABLE_FEATURE_IPV6
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 8226c6de8ac012f8c94c5a0e196d731876e2f7ec Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Mon, 3 Jul 2017 03:17:06 -0300
Subject: [PATCH 27/35] dietlibc/dnscruft: try to get dns server via command if
Subject: [PATCH 27/36] dietlibc/dnscruft: try to get dns server via command if
__sys_property_get fails
- bionic libc's property_get and __sys_property_get fail for statically compiled binaries
@ -46,5 +46,5 @@ index 142ffecd1..7804765b9 100644
if (parsesockaddr(propvalue,&_diet_res.nsaddr_list[_diet_res.nscount]))
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 207e3d751c707fca0401613112a30ba8a0ec6fbc Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Wed, 11 Aug 2021 23:54:04 -0300
Subject: [PATCH 28/35] ash history
Subject: [PATCH 28/36] ash history
allows ash history to work on Android
@ -103,5 +103,5 @@ index 53c140930..eded57508 100644
if (hp)
line_input_state->hist_file = xstrdup(hp);
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 9a6dc236900eb57c505888af6e4b974aaff30463 Mon Sep 17 00:00:00 2001
From: YU Jincheng <shana@zju.edu.cn>
Date: Wed, 29 Sep 2021 17:37:26 +0800
Subject: [PATCH 29/35] generalize "const trick"
Subject: [PATCH 29/36] generalize "const trick"
While at it, change all "__asm__" to "asm"
@ -218,5 +218,5 @@ index eded57508..9250b8f91 100644
varinit[i].flags = varinit_data[i].flags; \
varinit[i].var_text = varinit_data[i].var_text; \
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 9aa7088ec54da743229cfd8868112838e2dcc4c3 Mon Sep 17 00:00:00 2001
From: YU Jincheng <shana@zju.edu.cn>
Date: Sun, 10 Oct 2021 02:19:51 +0800
Subject: [PATCH 30/35] Make const ptr assign as function call in clang
Subject: [PATCH 30/36] Make const ptr assign as function call in clang
- This can act as memory barrier in clang to avoid
read before assign of a const ptr
@ -174,5 +174,5 @@ index 9250b8f91..150599f36 100644
varinit[i].flags = varinit_data[i].flags; \
varinit[i].var_text = varinit_data[i].var_text; \
--
2.35.0
2.35.1

View File

@ -0,0 +1,253 @@
From 250bb07b342e81239c71d5f787e82bb4f0b073b8 Mon Sep 17 00:00:00 2001
From: LoveSy <shana@zju.edu.cn>
Date: Sun, 20 Mar 2022 00:51:25 +0800
Subject: [PATCH 31/36] Replace `realpath` to BSD inplementation
---
libbb/Kbuild.src | 1 +
libbb/xrealpath.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 222 insertions(+)
create mode 100644 libbb/xrealpath.c
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index 5c75fc48c..88a302edb 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -115,6 +115,7 @@ lib-y += xrealloc_vector.o
# for android-busybox-ndk
lib-y += mntent_r.o
+lib-y += xrealpath.o
lib-$(CONFIG_MOUNT) += match_fstype.o
lib-$(CONFIG_UMOUNT) += match_fstype.o
diff --git a/libbb/xrealpath.c b/libbb/xrealpath.c
new file mode 100644
index 000000000..d4548859a
--- /dev/null
+++ b/libbb/xrealpath.c
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The names of the authors may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+char * __wrap_realpath(const char * __restrict path, char * __restrict resolved)
+{
+ struct stat sb;
+ char *p, *q, *s;
+ size_t left_len, resolved_len;
+ unsigned symlinks;
+ int m, slen;
+ char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
+
+ if (path == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ if (path[0] == '\0') {
+ errno = ENOENT;
+ return (NULL);
+ }
+ if (resolved == NULL) {
+ resolved = malloc(PATH_MAX);
+ if (resolved == NULL)
+ return (NULL);
+ m = 1;
+ } else
+ m = 0;
+ symlinks = 0;
+ if (path[0] == '/') {
+ resolved[0] = '/';
+ resolved[1] = '\0';
+ if (path[1] == '\0')
+ return (resolved);
+ resolved_len = 1;
+ left_len = strlcpy(left, path + 1, sizeof(left));
+ } else {
+ if (getcwd(resolved, PATH_MAX) == NULL) {
+ if (m)
+ free(resolved);
+ else {
+ resolved[0] = '.';
+ resolved[1] = '\0';
+ }
+ return (NULL);
+ }
+ resolved_len = strlen(resolved);
+ left_len = strlcpy(left, path, sizeof(left));
+ }
+ if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) {
+ if (m)
+ free(resolved);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+
+ /*
+ * Iterate over path components in `left'.
+ */
+ while (left_len != 0) {
+ /*
+ * Extract the next path component and adjust `left'
+ * and its length.
+ */
+ p = strchr(left, '/');
+ s = p ? p : left + left_len;
+ if (s - left >= sizeof(next_token)) {
+ if (m)
+ free(resolved);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ memcpy(next_token, left, s - left);
+ next_token[s - left] = '\0';
+ left_len -= s - left;
+ if (p != NULL)
+ memmove(left, s + 1, left_len + 1);
+ if (resolved[resolved_len - 1] != '/') {
+ if (resolved_len + 1 >= PATH_MAX) {
+ if (m)
+ free(resolved);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ resolved[resolved_len++] = '/';
+ resolved[resolved_len] = '\0';
+ }
+ if (next_token[0] == '\0') {
+ /* Handle consequential slashes. */
+ continue;
+ }
+ else if (strcmp(next_token, ".") == 0)
+ continue;
+ else if (strcmp(next_token, "..") == 0) {
+ /*
+ * Strip the last path component except when we have
+ * single "/"
+ */
+ if (resolved_len > 1) {
+ resolved[resolved_len - 1] = '\0';
+ q = strrchr(resolved, '/') + 1;
+ *q = '\0';
+ resolved_len = q - resolved;
+ }
+ continue;
+ }
+
+ /*
+ * Append the next path component and lstat() it.
+ */
+ resolved_len = strlcat(resolved, next_token, PATH_MAX);
+ if (resolved_len >= PATH_MAX) {
+ if (m)
+ free(resolved);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ if (lstat(resolved, &sb) != 0) {
+ if (m)
+ free(resolved);
+ return (NULL);
+ }
+ if (S_ISLNK(sb.st_mode)) {
+ if (symlinks++ > MAXSYMLINKS) {
+ if (m)
+ free(resolved);
+ errno = ELOOP;
+ return (NULL);
+ }
+ slen = readlink(resolved, symlink, sizeof(symlink) - 1);
+ if (slen < 0) {
+ if (m)
+ free(resolved);
+ return (NULL);
+ }
+ symlink[slen] = '\0';
+ if (symlink[0] == '/') {
+ resolved[1] = 0;
+ resolved_len = 1;
+ } else if (resolved_len > 1) {
+ /* Strip the last path component. */
+ resolved[resolved_len - 1] = '\0';
+ q = strrchr(resolved, '/') + 1;
+ *q = '\0';
+ resolved_len = q - resolved;
+ }
+
+ /*
+ * If there are any path components left, then
+ * append them to symlink. The result is placed
+ * in `left'.
+ */
+ if (p != NULL) {
+ if (symlink[slen - 1] != '/') {
+ if (slen + 1 >= sizeof(symlink)) {
+ if (m)
+ free(resolved);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ symlink[slen] = '/';
+ symlink[slen + 1] = 0;
+ }
+ left_len = strlcat(symlink, left,
+ sizeof(symlink));
+ if (left_len >= sizeof(left)) {
+ if (m)
+ free(resolved);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ }
+ left_len = strlcpy(left, symlink, sizeof(left));
+ } else if (!S_ISDIR(sb.st_mode) && p != NULL) {
+ if (m)
+ free(resolved);
+ errno = ENOTDIR;
+ return (NULL);
+ }
+ }
+
+ /*
+ * Remove trailing slash except when the resolved pathname
+ * is a single "/".
+ */
+ if (resolved_len > 1 && resolved[resolved_len - 1] == '/')
+ resolved[resolved_len - 1] = '\0';
+ return (resolved);
+}
--
2.35.1

View File

@ -1,7 +1,7 @@
From df5152c19bb3dc6a827f1de25cb773ad381a2669 Mon Sep 17 00:00:00 2001
From 683390d584c0c821fe5eb6ce1019ed60f5d43b31 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Fri, 3 Apr 2020 02:09:55 -0700
Subject: [PATCH 31/35] Fix incorrect assumptions about NDK
Subject: [PATCH 32/36] Fix incorrect assumptions about NDK
---
include/platform.h | 4 +++-
@ -51,5 +51,5 @@ index f02e8d14c..a6db67da9 100644
int pivot_root(const char *new_root, const char *put_old)
{
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 885beb5455f7603f608af4dd6c2cc1ba32fd8e5a Mon Sep 17 00:00:00 2001
From d4c52d4d0b13528849c1ac8231a9c2f1d7396ab2 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Fri, 7 Feb 2020 14:32:06 -0800
Subject: [PATCH 32/35] Add runtime toggle to enable standalone ash
Subject: [PATCH 33/36] Add runtime toggle to enable standalone ash
---
shell/ash.c | 42 ++++++++++++++++++++++++------------------
@ -115,5 +115,5 @@ index 150599f36..57a38f21a 100644
const char *hp;
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 82fc84e0392de12d3255187bbde0c2709265f84c Mon Sep 17 00:00:00 2001
From c0fcddedbbed301e214f95e3e7065f110e356f4d Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Thu, 25 Jun 2020 03:54:53 -0700
Subject: [PATCH 33/35] Resolve /proc/self/exe when re-exec ourselves
Subject: [PATCH 34/36] Resolve /proc/self/exe when re-exec ourselves
Use resolved path of /proc/self/exe to workaround Samsung kernel
blocking executables running as UID=0 in paths such as /proc.
@ -62,5 +62,5 @@ index 57a38f21a..f1104f108 100644
if (argc < 0)
/* Non-NULL minusc tells procargs that an embedded script is being run */
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From 88c03d1782e6d3198da955dddae93436f8e95de8 Mon Sep 17 00:00:00 2001
From 3942c732b4cff737ea948baed7d8d86495a2a5ae Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Sat, 2 May 2020 01:48:30 -0700
Subject: [PATCH 34/35] Disable SELinux features for install
Subject: [PATCH 35/36] Disable SELinux features for install
matchpathcon is not usable on Android
---
@ -32,5 +32,5 @@ index c0f1c538a..16c014384 100644
static const char install_longopts[] ALIGN1 =
IF_FEATURE_VERBOSE(
--
2.35.0
2.35.1

View File

@ -1,7 +1,7 @@
From ab6076ee7803bcfefc1fefcb5be7572bd1ba79af Mon Sep 17 00:00:00 2001
From 8178fff10870b9dab70f90794e07b7084569a294 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Thu, 21 Jan 2021 00:07:41 -0800
Subject: [PATCH 35/35] Allow running as libbusybox.so
Subject: [PATCH 36/36] Allow running as libbusybox.so
---
libbb/appletlib.c | 5 ++++-
@ -24,5 +24,5 @@ index a38b968fe..a07c85347 100644
applet_name++;
applet_name = bb_basename(applet_name);
--
2.35.0
2.35.1