|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Automatic Memory Management and Garbage CollectionIn C or C++, the programmer is responsible for allocating and deallocating memory and needs to keep track of the pointers to all the objects in memory. This can result in memory leaks, dangling pointers, null pointers, and other defects that are difficult to find and fix. Additionally, leaving memory management up to the programmer can allow for mischief. Manual allocation and deallocation of memory opens the door for unauthorized replication of objects, impersonation of trusted objects, and attacks on data consistency. By having automatic memory management, Java gets around these problems and, at the same time, makes life easier for the programmer. The following example shows how a programmer might go about impersonating a trusted class (for instance, the ClassLoader) if Java did not have automatic deallocation of memory. First, the program would create a legitimate object of class MyFakeClassLoader and make a reference to that object. Now, with a little sleight of hand and knowledge of how allocation and deallocation work, the programmer removes the object from memory but leaves the reference. He or she then instantiates a new instance of ClassLoader, which happens to be the exact same size, in the same memory space, and voila! The pointer now refers to the other class, and the programmer has access to methods and variables that are supposed to be private. This scenario is not possible in Java because of the automatic memory management. The Java automatic memory management system doesnt allow manual manipulation of references. The SecurityManager ClassThe Java security model is open to extension when new holes are found. A key to this is the SecurityManager class. This class is a generic class for implementing security policies and providing security wrappers around other parts of Java. This class does not get used by itselfit is simply a base for implementing security in other classes. Actual implementation of security in other objects is accomplished through subclassing the SecurityManager class. Although not a comprehensive list, this class contains methods to
As you might guess from the preceding list, the names of many of the methods in the java.lang.SecurityManager class begin with check. All but one of these checkXXX methods return if all is well or throw a SecurityException if there was a problem. Only checkTopLevelWindow returns a valuea Boolean. The following example of the use of the checkXXX methods is based on that in the Java 1.2 API documentation (found at http://java.sun.com/products/jdk/1.2/docs/api/java.lang.SecurityManager.html) for java.lang.SecurityManager: SecurityManager secMgr = System.getSecurityManager(); if (secMgr != null) { secMgr.checkXXX(arguments go here,… ); } Everything discussed so far in this section has been about Java as a whole. The language has no pointers whether you are working with applets or applications. The bytecode verifier and class loading mechanisms still apply. Applications in Java function like any other applications in any full-featured language, including direct memory access through use of native code. Some limitations on applets exist, however, that do not apply to applications. Time-Tested Applet SecurityJava would not have made the splash that it did only by being cross platform and object oriented. It was the Internet and applets that put it on the cover of Time magazine. The Internet is also where the biggest risks come for Java applets. Applets are limited Java programs, extended from class Applet, that execute within the users Web browser. Applets usually load from remote machines and are subject to severe limitations on the client machine. Untrusted applets arriving on the client machine are subject to the following file system and network restrictions:
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |