Possible bug in kvm_read()

Hi,

I have got the kvm.c from QNX CVS. There seems to be a possible bug in
kvm_read() function.
On my machine kvm_read() opens ‘/proc/98317/as’ file and seeks to the given
offset. After that, the following code is executed.

while (len)
{
if ((r = read(fd, data, len)) == -1)
{
fd = -1;
return -1;
}
len -= r;
data += r;
}

On my machine (QNX RTP 6) due to some reasons, the read() function reads
zero bytes (r=0)and does not return -1 (no error). Due to this, the above
loop becomes an infinite loop as long as read() keeps reading zero bytes.
Isn’t it a bug that the possibility of zero bytes being read is not
considered?

I would also like to know why read() is reading zero bytes on my machine? On
some other machines, the exact same code works perfectly. Any ideas?

Thanks in advance…

-Farooque

Farooque Khan <farooquek@concretioindia.com> wrote:

Hi,

I have got the kvm.c from QNX CVS. There seems to be a possible bug in
kvm_read() function.
On my machine kvm_read() opens ‘/proc/98317/as’ file and seeks to the given
offset. After that, the following code is executed.

while (len)
{
if ((r = read(fd, data, len)) == -1)
{
fd = -1;
return -1;
}
len -= r;
data += r;
}

On my machine (QNX RTP 6) due to some reasons, the read() function reads
zero bytes (r=0)and does not return -1 (no error). Due to this, the above
loop becomes an infinite loop as long as read() keeps reading zero bytes.
Isn’t it a bug that the possibility of zero bytes being read is not
considered?

I would say yes. It should be normal for read() to return 0 here – it
would mean that you are trying to read from some part of the processes
address space that doesn’t have anything mapped into it.

BUT, it might be an error to call kvm_read() on an area of memory
that isn’t mapped in. Still, this is definitely an unfriendly way
to handle that issue – it should check.

I would also like to know why read() is reading zero bytes on my machine? On
some other machines, the exact same code works perfectly. Any ideas?

read() returns zero bytes if there is no memory mapped at that address.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

David Gibbs <dagibbs@qnx.com> wrote:
: Farooque Khan <farooquek@concretioindia.com> wrote:
:> Hi,

:> I have got the kvm.c from QNX CVS. There seems to be a possible bug in
:> kvm_read() function.
:> On my machine kvm_read() opens ‘/proc/98317/as’ file and seeks to the given
:> offset. After that, the following code is executed.

:> while (len)
:> {
:> if ((r = read(fd, data, len)) == -1)
:> {
:> fd = -1;
:> return -1;
:> }
:> len -= r;
:> data += r;
:> }

:> On my machine (QNX RTP 6) due to some reasons, the read() function reads
:> zero bytes (r=0)and does not return -1 (no error). Due to this, the above
:> loop becomes an infinite loop as long as read() keeps reading zero bytes.
:> Isn’t it a bug that the possibility of zero bytes being read is not
:> considered?

: I would say yes. It should be normal for read() to return 0 here – it
: would mean that you are trying to read from some part of the processes
: address space that doesn’t have anything mapped into it.

: BUT, it might be an error to call kvm_read() on an area of memory
: that isn’t mapped in. Still, this is definitely an unfriendly way

It’s fixed in 6.2.

-seanb

Thanks all for all the answers.

-Farooque

“Sean Boudreau” <seanb@qnx.com> wrote in message
news:ad5led$eq7$1@nntp.qnx.com

David Gibbs <> dagibbs@qnx.com> > wrote:
: Farooque Khan <> farooquek@concretioindia.com> > wrote:
:> Hi,

:> I have got the kvm.c from QNX CVS. There seems to be a possible bug in
:> kvm_read() function.
:> On my machine kvm_read() opens ‘/proc/98317/as’ file and seeks to the
given
:> offset. After that, the following code is executed.

:> while (len)
:> {
:> if ((r = read(fd, data, len)) == -1)
:> {
:> fd = -1;
:> return -1;
:> }
:> len -= r;
:> data += r;
:> }

:> On my machine (QNX RTP 6) due to some reasons, the read() function
reads
:> zero bytes (r=0)and does not return -1 (no error). Due to this, the
above
:> loop becomes an infinite loop as long as read() keeps reading zero
bytes.
:> Isn’t it a bug that the possibility of zero bytes being read is not
:> considered?

: I would say yes. It should be normal for read() to return 0 here – it
: would mean that you are trying to read from some part of the processes
: address space that doesn’t have anything mapped into it.

: BUT, it might be an error to call kvm_read() on an area of memory
: that isn’t mapped in. Still, this is definitely an unfriendly way

It’s fixed in 6.2.

-seanb