Creation Zone

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 20 April 2006

Solaris: NULL pointer bugs & /usr/lib/0@0.so.1 library

Posted on 00:36 by Unknown
Some programmers assume that a NULL character pointer is the same as a pointer to a NULL string. However de-referencing a NULL pointer (ie., location 0x00000000 in the address space of a 32-bit process) results in a segmentation fault on Solaris; and hence the process dies with a signal SEGV. On Solaris, typically application text loads at 0x00001000. All the address space between 0x00000000 and 0x0000FFFF (that is about 64K of address space) is not used. I still need to find out why?. [Update: 04/26/06] According to Chris, first few pages were intentionally unmapped to catch poorly written code. Thanks Chris.

The following simple C program illustrates the NULL pointer de-referencing, and the subsequent process crash:
 % cat strlen.c
 #include <stdio.h>
 #include <string.h>

 int main()
 {
  char *string = NULL;

  printf("\nString length = %d", strlen(string));
  return (0);
 }

 % cc -g -o strlen strlen.c

 % ./strlen
 Segmentation Fault (core dumped)

 % dbx strlen core
 Reading strlen
 core file header read successfully
 Reading ld.so.1
 Reading libc.so.1
 Reading libdl.so.1
 Reading libc_psr.so.1
 program terminated by signal SEGV (no mapping at the fault address)
 0xff2b44e4: strlen+0x0080: ld [%o1], %o2
 Current function is main
  8 printf("\nString length = %d", strlen(string));


 (dbx) print $o1
 $o1 = 0

 (dbx) where
  [1] strlen(0x0, 0x0, 0x36a2c, 0x7efefeff, 0x81010100, 0xff3cdc4c), at 0xff2b44e4
 =>[2] main(), line 8 in "strlen.c"

 (dbx) whatis string
 char *string;

 (dbx) examine string
 0x00000000: 0x00000000

 (dbx) regs
 current frame: [2]
 g0-g1 0x00000000 0x00000000 0x00000000 0xff2b4464
 g2-g3 0x00000000 0x00000000 0x00000000 0x00000000
 g4-g5 0x00000000 0x00000000 0x00000000 0x00000000
 g6-g7 0x00000000 0x00000000 0x00000000 0x00000000
 o0-o1 0x00000000 0x00000000 0x00000000 0x00000000
 o2-o3 0x00000000 0x00036a2c 0x00000000 0x7efefeff
 o4-o5 0x00000000 0x81010100 0x00000000 0xff3cdc4c
 o6-o7 0x00000000 0xffbff8b8 0x00000000 0x00010c14
 l0-l1 0x00000000 0x00000000 0x00000000 0x00010c70
 l2-l3 0x00000000 0xff342070 0x00000000 0x00000000
 l4-l5 0x00000000 0x00000000 0x00000000 0x00000000
 l6-l7 0x00000000 0x00000000 0x00000000 0xff3ee7c4
 i0-i1 0x00000000 0x00000001 0x00000000 0xffbff984
 i2-i3 0x00000000 0xffbff98c 0x00000000 0x00020c00
 i4-i5 0x00000000 0x00000000 0x00000000 0x00000000
 i6-i7 0x00000000 0xffbff920 0x00000000 0x000107d0
 y 0x00000000 0x00000000
 ccr 0x00000000 0xfe400006
 pc 0x00000000 0x00010c14:main+0x14 call strlen [PLT] ! 0x20cdc
 npc 0x00000000 0xff2b44e8:strlen+0x84 inc 4, %o1

Observe that dbx is actually showing six arguments (addresses) instead of just one argument that is the address of the string being passed to this routine. These six arguments are the registers %o0 to %o5 which hold the outgoing arguments. You can match the arguments to strlen() in the call stack with the addresses in regs output. Note that the registers %i0 to %i5 hold the incoming arguments.

How to prevent the crash?

The recommended way is to modify the source code. The quick and dirty way is to pre-load the Solaris specific /usr/lib/0@0.so.1 library into process address space. /usr/lib/0@0.so.1 is an user compatibility library that Sun started shipping with Solaris 2.6, provides a mechanism that will cause location 0x00000000 {for 32-bit processes} to be mapped to a valid address containing the value 0. Note that the address 0x00000000 (or 0x0 in short) of the virtual address space is not mapped, by default.

eg.,
 % setenv LD_PRELOAD_32 /usr/lib/0@0.so.1

 %./strlen
 String length = 0

Read man page of run-time linker, ld.so.1, for more.

Acknowledgements:
Jim Fiori
___________________
Technorati tags: Solaris | Open Solaris | dbx
Email ThisBlogThis!Share to XShare to Facebook
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • *nix: Workaround to cannot find zipfile directory in one of file.zip or file.zip.zip ..
    Symptom: You are trying to extract the archived files off of a huge (any file with size > 2 GB or 4GB, depending on the OS) ZIP file with...
  • JDS: Installing Sun Java Desktop System 2.0
    This document will guide you through the process of installing JDS 2.0 on a PC from integrated CDROM images Requirements I...
  • Linux: Installing Source RPM (SRPM) package
    RPM stands for RedHat Package Manager. RPM is a system for installing and managing software & most common software package manager used ...
  • Solaris: malloc Vs mtmalloc
    Performance of Single Vs Multi-threaded application Memory allocation performance in single and multithreaded environments is an important a...
  • C/C++: Printing Stack Trace with printstack() on Solaris
    libc on Solaris 9 and later, provides a useful function called printstack , to print a symbolic stack trace to the specified file descripto...
  • Installing MySQL 5.0.51b from the Source Code on Sun Solaris
    Building and installing the MySQL server from the source code is relatively very easy when compared to many other OSS applications. At least...
  • Oracle Apps on T2000: ORA-04020 during Autoinvoice
    The goal of this brief blog post is to provide a quick solution to all Sun-Oracle customers who may run into a deadlock when a handful of th...
  • Siebel Connection Broker Load Balancing Algorithm
    Siebel server architecture supports spawning multiple application object manager processes. The Siebel Connection Broker, SCBroker, tries to...
  • 64-bit dbx: internal error: signal SIGBUS (invalid address alignment)
    The other day I was chasing some lock contention issue with a 64-bit application running on Solaris 10 Update 1; and stumbled with an unexpe...
  • Oracle 10gR2/Solaris x64: Fixing ORA-20000: Oracle Text errors
    First, some facts: * Oracle Applications 11.5.10 (aka E-Business Suite 11 i ) database is now supported on Solaris 10 for x86-64 architectur...

Categories

  • 80s music playlist
  • bandwidth iperf network solaris
  • best
  • black friday
  • breakdown database groups locality oracle pmap sga solaris
  • buy
  • deal
  • ebiz ebs hrms oracle payroll
  • emca oracle rdbms database ORA-01034
  • friday
  • Garmin
  • generic+discussion software installer
  • GPS
  • how-to solaris mmap
  • impdp ora-01089 oracle rdbms solaris tips upgrade workarounds zombie
  • Magellan
  • music
  • Navigation
  • OATS Oracle
  • Oracle Business+Intelligence Analytics Solaris SPARC T4
  • oracle database flashback FDA
  • Oracle Database RDBMS Redo Flash+Storage
  • oracle database solaris
  • oracle database solaris resource manager virtualization consolidation
  • Oracle EBS E-Business+Suite SPARC SuperCluster Optimized+Solution
  • Oracle EBS E-Business+Suite Workaround Tip
  • oracle lob bfile blob securefile rdbms database tips performance clob
  • oracle obiee analytics presentation+services
  • Oracle OID LDAP ADS
  • Oracle OID LDAP SPARC T5 T5-2 Benchmark
  • oracle pls-00201 dbms_system
  • oracle siebel CRM SCBroker load+balancing
  • Oracle Siebel Sun SPARC T4 Benchmark
  • Oracle Siebel Sun SPARC T5 Benchmark T5-2
  • Oracle Solaris
  • Oracle Solaris Database RDBMS Redo Flash F40 AWR
  • oracle solaris rpc statd RPC troubleshooting
  • oracle solaris svm solaris+volume+manager
  • Oracle Solaris Tips
  • oracle+solaris
  • RDC
  • sale
  • Smartphone Samsung Galaxy S2 Phone+Shutter Tip Android ICS
  • solaris oracle database fmw weblogic java dfw
  • SuperCluster Oracle Database RDBMS RAC Solaris Zones
  • tee
  • thanksgiving sale
  • tips
  • TomTom
  • windows

Blog Archive

  • ►  2013 (16)
    • ►  December (3)
    • ►  November (2)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (2)
    • ►  January (1)
  • ►  2012 (14)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (2)
  • ►  2011 (15)
    • ►  December (2)
    • ►  November (1)
    • ►  October (2)
    • ►  September (1)
    • ►  August (2)
    • ►  July (1)
    • ►  May (2)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2010 (19)
    • ►  December (3)
    • ►  November (1)
    • ►  October (2)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (5)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2009 (25)
    • ►  December (1)
    • ►  November (2)
    • ►  October (1)
    • ►  September (1)
    • ►  August (2)
    • ►  July (2)
    • ►  June (1)
    • ►  May (2)
    • ►  April (3)
    • ►  March (1)
    • ►  February (5)
    • ►  January (4)
  • ►  2008 (34)
    • ►  December (2)
    • ►  November (2)
    • ►  October (2)
    • ►  September (1)
    • ►  August (4)
    • ►  July (2)
    • ►  June (3)
    • ►  May (3)
    • ►  April (2)
    • ►  March (5)
    • ►  February (4)
    • ►  January (4)
  • ►  2007 (33)
    • ►  December (2)
    • ►  November (4)
    • ►  October (2)
    • ►  September (5)
    • ►  August (3)
    • ►  June (2)
    • ►  May (3)
    • ►  April (5)
    • ►  March (3)
    • ►  February (1)
    • ►  January (3)
  • ▼  2006 (40)
    • ►  December (2)
    • ►  November (6)
    • ►  October (2)
    • ►  September (2)
    • ►  August (1)
    • ►  July (2)
    • ►  June (2)
    • ►  May (4)
    • ▼  April (5)
      • The Reason Is You
      • Make a noise and make it clear
      • Solaris: NULL pointer bugs & /usr/lib/0@0.so.1 lib...
      • Building Enterprise Applications with Sun Studio P...
      • My Favorite Music VI
    • ►  March (5)
    • ►  February (3)
    • ►  January (6)
  • ►  2005 (72)
    • ►  December (5)
    • ►  November (2)
    • ►  October (6)
    • ►  September (5)
    • ►  August (5)
    • ►  July (10)
    • ►  June (8)
    • ►  May (9)
    • ►  April (6)
    • ►  March (6)
    • ►  February (5)
    • ►  January (5)
  • ►  2004 (36)
    • ►  December (1)
    • ►  November (5)
    • ►  October (12)
    • ►  September (18)
Powered by Blogger.

About Me

Unknown
View my complete profile