|
From: <sv...@va...> - 2015-04-06 14:29:53
|
Author: florian
Date: Mon Apr 6 15:29:45 2015
New Revision: 15068
Log:
The linux launcher showed some odd behaviour. When given a shell script
named 'now' with this contents:
#!
/bin/date
the platform selection logic does this:
--11196:1:launcher no tool requested, defaulting to 'memcheck'
--11196:2:launcher selecting platform for './now'
--11196:2:launcher selecting platform for './now'
--11196:2:launcher opened './now'
--11196:2:launcher read 13 bytes from './now'
--11196:2:launcher selecting platform for ''
--11196:2:launcher selecting platform for '/home/florian/bin/'
--11196:2:launcher opened '/home/florian/bin/'
--11196:2:launcher selected platform 'unknown'
--11196:1:launcher no platform detected, defaulting platform to 'amd64-linux'
That is not quite right. Instead the platform should be determined by
examining the default shell.
Additionally, define VKI_BINPRM_BUF_SIZE because on linux only that many
characters are considered on a #! line. C.f. <linux>/fs/binfmt_script.c
m_ume/* needs to be adapted as well but that is a different patch.
Modified:
trunk/coregrind/launcher-linux.c
trunk/include/vki/vki-linux.h
Modified: trunk/coregrind/launcher-linux.c
==============================================================================
--- trunk/coregrind/launcher-linux.c (original)
+++ trunk/coregrind/launcher-linux.c Mon Apr 6 15:29:45 2015
@@ -1,3 +1,4 @@
+/* -*- mode: C; c-basic-offset: 3; -*- */
/*--------------------------------------------------------------------*/
/*--- Launching valgrind m_launcher.c ---*/
@@ -156,24 +157,39 @@
if (header[0] == '#' && header[1] == '!') {
int i = 2;
- char *interp = (char *)header + 2;
+ STATIC_ASSERT(VKI_BINPRM_BUF_SIZE < sizeof header);
+ if (n_bytes > VKI_BINPRM_BUF_SIZE)
+ n_bytes = VKI_BINPRM_BUF_SIZE - 1;
+ header[n_bytes] = '\0';
+ char *eol = strchr(header, '\n');
+ if (eol != NULL)
+ *eol = '\0';
+
// Skip whitespace.
- while (1) {
- if (i == n_bytes) return NULL;
- if (' ' != header[i] && '\t' != header[i]) break;
+ while (header[i] == ' '|| header[i] == '\t')
i++;
- }
// Get the interpreter name.
- interp = &header[i];
- while (1) {
- if (i == n_bytes) break;
- if (isspace(header[i])) break;
- i++;
+ const char *interp = header + i;
+
+ if (header[i] == '\0') {
+ // No interpreter was found; fall back to default shell
+# if defined(VGPV_arm_linux_android) \
+ || defined(VGPV_x86_linux_android) \
+ || defined(VGPV_mips32_linux_android) \
+ || defined(VGPV_arm64_linux_android)
+ interp = "/system/bin/sh";
+# else
+ interp = "/bin/sh";
+# endif
+ } else {
+ while (header[i]) {
+ if (header[i] == ' ' || header[i] == '\t') break;
+ i++;
+ }
+ header[i] = '\0';
}
- if (i == n_bytes) return NULL;
- header[i] = '\0';
platform = select_platform(interp);
Modified: trunk/include/vki/vki-linux.h
==============================================================================
--- trunk/include/vki/vki-linux.h (original)
+++ trunk/include/vki/vki-linux.h Mon Apr 6 15:29:45 2015
@@ -4610,6 +4610,11 @@
#define VKI_SECCOMP_MODE_FILTER 2
+//----------------------------------------------------------------------
+// From linux-3.19.3/include/uapi/linux/binfmts.h
+//----------------------------------------------------------------------
+#define VKI_BINPRM_BUF_SIZE 128
+
#endif // __VKI_LINUX_H
/*--------------------------------------------------------------------*/
|