1218885Sdim#!/usr/bin/ksh 2218885Sdim# 3218885Sdim# CDDL HEADER START 4218885Sdim# 5218885Sdim# The contents of this file are subject to the terms of the 6218885Sdim# Common Development and Distribution License (the "License"). 7218885Sdim# You may not use this file except in compliance with the License. 8218885Sdim# 9218885Sdim# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10218885Sdim# or http://www.opensolaris.org/os/licensing. 11218885Sdim# See the License for the specific language governing permissions 12218885Sdim# and limitations under the License. 13218885Sdim# 14249423Sdim# When distributing Covered Code, include this CDDL HEADER in each 15249423Sdim# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16249423Sdim# If applicable, add the following below this CDDL HEADER, with the 17218885Sdim# fields enclosed by brackets "[]" replaced with your own identifying 18218885Sdim# information: Portions Copyright [yyyy] [name of copyright owner] 19226584Sdim# 20218885Sdim# CDDL HEADER END 21249423Sdim# 22234353Sdim 23218885Sdim# 24218885Sdim# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25263508Sdim# Use is subject to license terms. 26263508Sdim# 27218885Sdim 28263508Sdim# 29218885Sdim# This test verifies that a program that corrupts its own environment 30218885Sdim# without inducing a crash does not crash solely due to drti.o's use of 31263508Sdim# getenv(3C). 32234353Sdim# 33263508Sdim 34263508SdimPATH=/usr/bin:/usr/sbin:$PATH 35263508Sdim 36263508Sdimif (( $# != 1 )); then 37263508Sdim print -u2 'expected one argument: <dtrace-path>' 38234353Sdim exit 2 39263508Sdimfi 40226584Sdim 41249423Sdim# 42249423Sdim# jdtrace does not implement the -h option that is required to generate 43249423Sdim# C header files. 44249423Sdim# 45226584Sdimif [[ "$1" == */jdtrace ]]; then 46218885Sdim exit 0 47218885Sdimfi 48226584Sdim 49218885Sdimdtrace="$1" 50226584Sdimstartdir="$PWD" 51218885Sdimdir=$(mktemp -td drtiXXXXXX) 52218885Sdimif (( $? != 0 )); then 53218885Sdim print -u2 'Could not create safe temporary directory' 54218885Sdim exit 2 55218885Sdimfi 56218885Sdim 57218885Sdimcd "$dir" 58226584Sdim 59226584Sdimcat > Makefile <<EOF 60218885Sdimall: main 61218885Sdim 62218885Sdimmain: main.o prov.o 63234353Sdim \$(CC) -o main main.o prov.o 64218885Sdim 65263508Sdimmain.o: main.c prov.h 66218885Sdim \$(CC) -c main.c 67218885Sdim 68218885Sdimprov.h: prov.d 69226584Sdim $dtrace -h -s prov.d 70226584Sdim 71218885Sdimprov.o: prov.d main.o 72226584Sdim $dtrace -G -32 -s prov.d main.o 73226584SdimEOF 74226584Sdim 75226584Sdimcat > prov.d <<EOF 76226584Sdimprovider tester { 77226584Sdim probe entry(); 78218885Sdim}; 79226584SdimEOF 80226584Sdim 81226584Sdimcat > main.c <<EOF 82226584Sdim#include <stdlib.h> 83234353Sdim#include <sys/sdt.h> 84234353Sdim#include "prov.h" 85234353Sdim 86234353Sdimint 87234353Sdimmain(int argc, char **argv, char **envp) 88234353Sdim{ 89249423Sdim envp[0] = (char*)0xff; 90226584Sdim TESTER_ENTRY(); 91249423Sdim return 0; 92226584Sdim} 93226584SdimEOF 94226584Sdim 95226584Sdimmake > /dev/null 96226584Sdimstatus=$? 97226584Sdimif (( $status != 0 )) ; then 98226584Sdim print -u2 "failed to build" 99218885Sdimelse 100218885Sdim ./main 101226584Sdim status=$? 102226584Sdimfi 103226584Sdim 104226584Sdimcd "$startdir" 105226584Sdimrm -rf "$dir" 106226584Sdim 107226584Sdimexit $status 108226584Sdim