Page 1 of 2
Strange problem
Posted: Mon Jul 19, 2010 4:00 am
by finarfin
Hi all,
I use for all testing commands a data structure:
Code: Select all
struct devel {
const char cmd_testname[CMD_LEN];
void (*func)(void);
}
And i use an array of these structures every time i launch a test command.
So that array has 11 elements, and everithing working fine. But now i adde a new command, and something goes wrong.
In fact now, when i try to log-in my os (with a very basic login method based on a username a simply file passwd) the function called for user checking is called (and i'm sure of it) but two strange thing happens:
1. printf doesn't work
2. when i call:
the function open didn't receive the path, in fact if i try to print it on the screen (into open function printf restarts to work) i receive an empty string.
if i force the user_check function to success (so every username inserted is accepted) the rest of the operatiing system works fine.
I don't have any idea why it happen, probably a memory problem, but where to start?
Any help?
P.s. sorry for my bad english
Re: Strange problem :)
Posted: Mon Jul 19, 2010 4:31 am
by Combuster
Due to the lack of useful information and excess of smileys, I'll resort to my crystal ball.
Custom bootloader reading a fixed amount of sectors?
Re: Strange problem :)
Posted: Mon Jul 19, 2010 4:34 am
by Solar
Good one.
Simple memory corruption would be my #2 guess.
Re: Strange problem :)
Posted: Mon Jul 19, 2010 5:22 am
by gerryg400
P.s. sorry for my bad english
_________________
Elen sila lumen omentielvo
Your English is better than your Elvish. Try...
Elen sila lumenn' omentielvo
Re: Strange problem :)
Posted: Mon Jul 19, 2010 5:47 am
by Fanael
gerryg400 wrote:P.s. sorry for my bad english
_________________
Elen sila lumen omentielvo
Your English is better than your Elvish. Try...
Elen sila lumenn' omentielvo
Better still:
Elen síla lúmenn' omentielvo
Also, there's no such thing as "Elvish language". There are many elvish languages, and this one is called Quenya.</offtopic>
Re: Strange problem
Posted: Mon Jul 19, 2010 6:54 am
by finarfin
1. removed emoticons (only 1 left)
2. Corrected mi signature
And now, back to my problem,
i use grub as bootloader.
Memory corruption? is possible.
Here you find where the code user_chk is called.
Code: Select all
do {
printf(LNG_USER);
scanf ("%23s",current_user.username);
printf(LNG_USER_R);
#ifdef PWD_CHECK
printf(LNG_PWD);
scanf ("%23s",password);
#endif
printf("Vediamo %s\n", current_user.username);
ret_val = user_chk(current_user.username, password);
} while ((!strlen(current_user.username) || ret_val!=1));
and the function user_chk:
Code: Select all
int user_chk(char *username, char* usr_pwd){
int fd = -1;
struct passwd_user checking_user;
printf("Username provided: %s\n", username);
fd = open("/passwd", O_RDONLY,0);
if(fd<0) return 0;
while(user_get(fd, &checking_user)==2){
#ifdef PWD_CHECK
if(!strcmp(username, checking_user.username) && !strcmp(usr_pwd, checking_user.password)) return 1;
#else
if(!strcmp(username, checking_user.username)) return 1;
#endif
}
close(fd);
return 0;
}
This printf:
printf("Username provided: %s\n", username);
isn't showed.
And inside open(...) "/passwd" became empty string
And the structure checking_user:
Code: Select all
struct passwd_user {
char username[50];
char password[50];
};
Re: Strange problem
Posted: Mon Jul 19, 2010 12:21 pm
by Combuster
Still not enough information. Right now, my crystal ball says: "Solar's right"
How do you know for sure that the problem lies within the piece of code you posted? Is the problem actually in that piece of code?
Re: Strange problem
Posted: Mon Jul 19, 2010 2:40 pm
by finarfin
I only showed where the problem happens. For showing where
Not that the problem is there. That pieces of code are involved.
the problem is that i don't know who is involved in the problem, why i have now some strings that are emptied and why all that happens only inside one function.
And probably is a memory corruption problem.
So any suggestion on how to find where, when it happens?
Re: Strange problem
Posted: Mon Jul 19, 2010 5:03 pm
by Brynet-Inc
finarfin wrote:...the problem is that i don't know who is involved in the problem..
I have my suspicions about Combuster, practising magic, wizards are always up to such tricks.
Re: Strange problem
Posted: Tue Jul 20, 2010 8:51 am
by Solar
finarfin wrote:So any suggestion on how to find where, when it happens?
Solar's Machete.
Re: Strange problem
Posted: Sat Jul 24, 2010 12:51 pm
by finarfin
The problem appear when the kernel dimension grow of 4096 bytes.
For example the kernel work until it is 80061 bytes, and it stop to work when it became 84157 bytes
(the dimension grow by 4k each time).
So i can't figure why it happens. Surely it's a memory problem. And doing some memory dump i notice that the memory area where my strings are supposed to be, are full of 0's.
Re: Strange problem
Posted: Sat Jul 24, 2010 1:46 pm
by JohnnyTheDon
Check your linker script.
Re: Strange problem
Posted: Sat Jul 24, 2010 3:18 pm
by finarfin
Here, is my linker script:
Code: Select all
OUTPUT_FORMAT("binary")
OUTPUT_ARCH(i386)
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
Re: Strange problem
Posted: Sat Jul 24, 2010 3:37 pm
by JohnnyTheDon
You might want to try running objdump on your kernel image to see if anything looks messed up (pay attention to any LOAD program headers). Also check any code that might be trashing large amounts of memory (a broken memcpy implementation, for example).
Re: Strange problem
Posted: Sat Jul 24, 2010 10:29 pm
by gerryg400
I don't know what your problem is but let me recommend that you use ELF file format instead of binary. Grub will still load it. But the best thing is, you can inspect your code with objdump and see symbols in the disassembled code.