Skip to contentSkip to conversation

bug in kernel

DISCUSSION Evgeniy 5 participants 6 messages Mar 14, 2005

lore
Share & tools
lore

Evgeniy

author
#0 lore raw

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

#1 lore raw
Quoted 10 lines · Evgeniy

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);
}

Quoted 5 lines

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 ?

#2 lore raw
Quoted 11 lines · Arjan van de Ven
Quoted 10 lines · Evgeniy

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);
}

Quoted 8 lines
Quoted 5 lines

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

#3 lore raw
In reply to Evgeniy
Quoted 7 lines · Evgeniy

#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.

#4 lore raw
In reply to Evgeniy

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

Quoted 9 lines

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

Signature · 8 lines
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>
#5 lore raw
In reply to Evgeniy
Quoted 10 lines · Evgeniy

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);
}

Quoted 2 lines

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.