[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: read error
- From: HyperHacker <hyperhacker@...>
- Date: Tue, 8 Nov 2011 23:34:36 -0700
On Tue, Nov 8, 2011 at 23:28, Juris Kalnins <juris@mt.lv> wrote:
> On Tue, 08 Nov 2011 16:48:10 +0200, Roberto Ierusalimschy
> <roberto@inf.puc-rio.br> wrote:
>
>> I am trying to test errors in read operations (io.read - io.line). Does
>> anyone know a reliable/automatic way to generate a read error on
>> Linux? (That is, a situation where fread returns EOF and ferror returns
>> not zero.)
>>
>> -- Roberto
>>
>
> Something like how the fakeroot does the libc call hijacking.
> You can write a dynamic library that defines some libc functions:
>
> static size_t original_fread(....) = (size_t (*) dlsym(RTLD_NEXT, fread);
>
> extern size_t fread(....) {
> size_t ret = original_fread(....);
> /* some logic that injects errors */
> return ret;
> }
>
>
> and then run your program like this:
>
> LD_PRELOAD=fakelibc.so ./test-program
>
>
Reading from /dev/null will give you EOF.
--
Sent from my toaster.