2005-03-14 14:46:16

by Evgeniy

[permalink] [raw]
Subject: bug in kernel

Here is a simple program.

#include <stdio.h>
#include <errno.h>
main(){
int err;
err=read(0,NULL,6);
printf("%d %d\n",err,errno);
}

I think that it should be an error : Null pointer assignment, like in windows.
But in practise it is not so.
Mandrake Linux kernel 2.4.21-0.13mdk
I am a programmer too and i am very interested to solve this problem. Please,
send me fragment of sourse code of kernel with this bug.
Thanks.
Sorry for my English


2005-03-14 14:51:17

by Arjan van de Ven

[permalink] [raw]
Subject: Re: bug in kernel

On Mon, 2005-03-14 at 17:48 +0300, Evgeniy wrote:
> Here is a simple program.
>
> #include <stdio.h>
> #include <errno.h>
> main(){
> int err;
> err=read(0,NULL,6);
> printf("%d %d\n",err,errno);
> }
>
> I think that it should be an error : Null pointer assignment, like in windows.
> But in practise it is not so.
> Mandrake Linux kernel 2.4.21-0.13mdk
> I am a programmer too and i am very interested to solve this problem. Please,
> send me fragment of sourse code of kernel with this bug.

well what is the value of errno ?
-EFAULT by chance ?



2005-03-14 14:55:39

by Arjan van de Ven

[permalink] [raw]
Subject: Re: bug in kernel

On Mon, 2005-03-14 at 15:51 +0100, Arjan van de Ven wrote:
> On Mon, 2005-03-14 at 17:48 +0300, Evgeniy wrote:
> > Here is a simple program.
> >
> > #include <stdio.h>
> > #include <errno.h>
> > main(){
> > int err;
> > err=read(0,NULL,6);
> > printf("%d %d\n",err,errno);
> > }
> >
> > I think that it should be an error : Null pointer assignment, like in windows.
> > But in practise it is not so.
> > Mandrake Linux kernel 2.4.21-0.13mdk
> > I am a programmer too and i am very interested to solve this problem. Please,
> > send me fragment of sourse code of kernel with this bug.
>
> well what is the value of errno ?
> -EFAULT by chance ?

note that you need to include <unistd.h> for the proper read() prototype
btw

2005-03-14 15:28:00

by Bernhard Rosenkraenzer

[permalink] [raw]
Subject: Re: bug in kernel

On Monday 14 March 2005 15:48, Evgeniy wrote:
> #include <stdio.h>
> #include <errno.h>
> main(){
> int err;
> err=read(0,NULL,6);
> printf("%d %d\n",err,errno);
> }

On my box (2.6.11), that does exactly what it is supposed to do -- "-1 14"
14 == EFAULT == "Bad Address", which is what NULL is...

Btw, printf("%d %d %s\n", err, errno, strerror(errno)); gives you a more
readable error, that would immediately show you did get the right error.

2005-03-14 15:47:57

by Pat Kane

[permalink] [raw]
Subject: Re: bug in kernel

I ran the little test program on my 2.4.26 Knoppix system, and got the
following two results:

strace a.out < /dev/tty
...
read(0, NULL, 6) = 1
...

strace a.out < /dev/zero
...
read(0, 0, 6) = -1 EFAULT (Bad address)
...

The first case looks broken.

Pat
---



2005-03-14 15:56:52

by Martin Zwickel

[permalink] [raw]
Subject: Re: bug in kernel

On Mon, 14 Mar 2005 17:48:05 +0300
Evgeniy <[email protected]> bubbled:

> Here is a simple program.
>
> #include <stdio.h>
> #include <errno.h>
> main(){
> int err;
> err=read(0,NULL,6);
> printf("%d %d\n",err,errno);
> }

Results:
# ./a < /dev/zero
read(0, 0, 6) = -1 EFAULT (Bad address)
-1 14 Bad address

So everything is fine...

Regards,
Martin

--
MyExcuse:
I'd love to help you -- it's just that the Boss won't let me near the
computer.

Martin Zwickel <[email protected]>
Research & Development

TechnoTrend AG <http://www.technotrend.de>


Attachments:
(No filename) (189.00 B)

2005-03-14 16:59:55

by linux-os (Dick Johnson)

[permalink] [raw]
Subject: Re: bug in kernel

On Mon, 14 Mar 2005, Evgeniy wrote:

> Here is a simple program.
>
> #include <stdio.h>
> #include <errno.h>
> main(){
> int err;
> err=read(0,NULL,6);
> printf("%d %d\n",err,errno);
> }
>
> I think that it should be an error : Null pointer assignment, like in windows.
> But in practise it is not so.

It is an error. It will wait <forever> until you enter the [Enter]
key (it's reading from STDIN_FILENO). Then it will return -1 which
means there was an error, the error code in errno is 14 (EFAULT)
or "bad address".

You can configure user-mode code to "seg-fault" upon receiving
such an error. It can print a nasty message and leave a worthless
core file in your directory.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.