This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Determining if an address is valid prior to using it.
- From: Nathan Weyer <nweyer at meritgames dot com>
- To: jimmie davis <jimmie dot davis at l-3com dot com>
- Cc: libc-help at sourceware dot org
- Date: Wed, 23 Jul 2008 16:33:56 -0400 (EDT)
- Subject: Re: Determining if an address is valid prior to using it.
This is the only way I am aware of.
---------------------------------------------------------------
bool AddyIsOk;
u32* JunkAddy;
void* JunkInfo;
sigjmp_buf test_sigjump_buf;
void test_signal_fxn(int signo)
{
// REPORT("Address test failed!\n");
AddyIsOk = false;
JunkAddy = (u32*)&JunkAddy;
siglongjmp(test_sigjump_buf,1);
}
bool debug_check_address(void* addy)
{
// fprintf(stderr,"Testing [%p]\n",addy);
struct sigaction test_sig;
struct sigaction save_sig;
AddyIsOk = true;
test_sig.sa_handler = test_signal_fxn;
sigemptyset(&test_sig.sa_mask);
test_sig.sa_flags = 0;
JunkAddy = (u32*)addy;
if(sigaction(SIGSEGV,&test_sig,&save_sig) == -1)
{
perror("Could Not Install TestSig : ");
return false;
}
if(sigsetjmp(test_sigjump_buf,1) == 0)
{
JunkInfo = (void*)(*JunkAddy);
JunkInfo = (void*)(((u32)(JunkInfo))+4);
}
if(sigaction(SIGSEGV,&save_sig,NULL) == -1)
{
perror("Could Not Revert Sig : ");
return false;
}
// fprintf(stderr,"[%p] is [%s]\n",addy,AddyIsOk?"Ok":"Bad");
return AddyIsOk;
}
----- Original Message -----
From: "jimmie davis" <jimmie.davis@l-3com.com>
To: libc-help@sourceware.org
Sent: Wednesday, July 23, 2008 4:06:00 PM GMT -05:00 US/Canada Eastern
Subject: Determining if an address is valid prior to using it.
Given an arbitrary address, is it possible to test and see if it is in
the process's address space ?
My current technique is to create a new thread, then access the memory
from that thread. Then if it did not segfault i know the address was
valid.
Is there a better way to do this ?
thanks,
bud davis
"Buy the ticket, take the ride."
Hunter S. Thompson