I reckon fpat is not in stack since is a constant string. However,
both cases are working on my box:

er...@manteca ~ $ ./test
/proc/4424
main, main memory: cp: 4425, pp: 4424, f: /proc/4424/mem, fd: 3, read:
10, errno: Success
child, child memory: cp: 4425, pp: 4424, f: /proc/4425/mem, fd: 3,
read: 10, errno: Success
er...@manteca ~ $ uname -a
Linux manteca 2.6.32.7 #7 SMP Wed Feb 3 13:26:43 UYST 2010 x86_64 GNU/Linux


On 13 May 2010 16:47, mobi phil <[email protected]> wrote:
> sorry to pollute... but my conclusion is probably interesting for you
> as well... it works with pread... which means is better than lseek +
> read, as it is only one kernel call...
>
> however the problem was with the variable ... I was failing to read
> due to the variable... I can access fpat's address that , but not
> buff, that is allocated on the stack... It is a strange limitation...
> It seems that you simply cannot access the stack...
>
> #include <sys/types.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <string.h>
> #include <errno.h>
>
> int main()
> {
>   char *fpat = "/proc/%d/mem";
>   pid_t pp = getpid();
>   char buff[100];
>   pid_t cp;
>   char bb[1000];
>   if( (cp = fork()) == 0)
>   {
>      cp = getpid(); //child
>
>      sprintf(buff, fpat, cp);
>      int fd = open(buff, O_RDONLY  );
>
>      //int s = pread(fd, bb, 10, buff ); //fails!!!
>      int s = pread(fd, bb, 10, fpat );//works... why? both are
> allocated on the stack
>      printf("child, child memory: cp: %d, pp: %d, f: %s, fd: %d,
> read: %d, errno: %s\n",
>            cp, pp, buff, fd, s, strerror(errno));
>
>      _exit(1);
>   }
>   else
>   {
>      sprintf(buff, fpat, pp);
>      int fd = open(buff, O_RDONLY  );
>
>      //int s = pread(fd, bb, 10, buff ); //fails!!!
>      int s = pread(fd, bb, 10, fpat ); //works... , both are
> allocated on the stack...
>      write(1,bb, 10);
>      write(1,"\n",1);
>      printf("main, main memory: cp: %d, pp: %d, f: %s, fd: %d, read:
> %d, errno: %s\n",
>            cp, pp, buff, fd, s, strerror(errno));
>
>   }
> }
> ~
>
>
>
>
> --
> rgrds,
> mobi phil
>
> being mobile, but including technology
> http://mobiphil.com
> _______________________________________________
> radare mailing list
> [email protected]
> http://lists.nopcode.org/listinfo.cgi/radare-nopcode.org
>



-- 
There is a crack, a crack in everything.
That's how the wine gets in.
_______________________________________________
radare mailing list
[email protected]
http://lists.nopcode.org/listinfo.cgi/radare-nopcode.org

Reply via email to