1 /************************************************************************* |
|
2 /* BufferOverflow.java -- Tests PushbackInputStream buffer overflows. |
|
3 /* |
|
4 /* Copyright (c) 1998 Free Software Foundation, Inc. |
|
5 /* Written by Aaron M. Renn (arenn@urbanophile.com) |
|
6 /* |
|
7 /* This program is free software; you can redistribute it and/or modify |
|
8 /* it under the terms of the GNU General Public License as published |
|
9 /* by the Free Software Foundation, either version 2 of the License, or |
|
10 /* (at your option) any later version. |
|
11 /* |
|
12 /* This program is distributed in the hope that it will be useful, but |
|
13 /* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 /* GNU General Public License for more details. |
|
16 /* |
|
17 /* You should have received a copy of the GNU General Public License |
|
18 /* along with this program; if not, write to the Free Software Foundation |
|
19 /* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA |
|
20 /*************************************************************************/ |
|
21 |
|
22 // Tags: JDK1.1 |
|
23 |
|
24 package gnu.testlet.java.io.PushbackInputStream; |
|
25 |
|
26 import gnu.testlet.Testlet; |
|
27 import gnu.testlet.TestHarness; |
|
28 import java.io.*; |
|
29 |
|
30 public class BufferOverflow implements Testlet |
|
31 { |
|
32 |
|
33 public void |
|
34 test(TestHarness harness) |
|
35 { |
|
36 String str = "Once when I was in fourth grade, my friend Lloyd\n" + |
|
37 "Saltsgaver and I got in trouble for kicking a bunch of\n" + |
|
38 "Kindergartners off the horse swings so we could play a game\n" + |
|
39 "of 'road hog'\n"; |
|
40 |
|
41 try |
|
42 { |
|
43 PushbackInputStream pist = new PushbackInputStream( |
|
44 new StringBufferInputStream(str), 10); |
|
45 |
|
46 byte[] read_buf = new byte[12]; |
|
47 |
|
48 pist.read(read_buf); |
|
49 pist.unread(read_buf); |
|
50 harness.debug("Failed overflow test"); |
|
51 harness.check(false); |
|
52 } |
|
53 catch(IOException e) |
|
54 { |
|
55 harness.debug("Got expected exception: " + e); |
|
56 harness.check(true); |
|
57 } |
|
58 } |
|
59 |
|
60 } // class BufferOverflow |
|
61 |
|