Follow us on Twitter!
Understanding is the answer, hatred is the problem, and hackers are the slaves abused and destroyed in the process of peace online - Deshouleres
Monday, April 21, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 31
Guests Online: 30
Members Online: 1

Registered Members: 82851
Newest Member: darthvador
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Reading a config file in C


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-03-10 19:08
So I have been making an IRC bot in C and I decided to use a configuration file for all the settings. So the user can just edit it to his/her liking and you don't need to recompile it or anything. I have a struct with all the variables needed. Then when main() starts it passes an instance of the struct to load_config() by reference. Then this is where I am having trouble. I fill in the struct's host from the file then back in main I print it out and it does print out 127.0.0.1 but on the next line it has some weird looking chacters (this is what i compiled http://pastebin.c. . .). Furthermore when I tried to fill out another variable in my struct it over writes the structs host. (this prints out questions.txt for both host and location, and some additional random characters http://pastebin.c. . .) I really don't know why this is happening, so any suggestions or ideas would be very much appreciated. O and keep in mind the above code was just taken out of the main program for debugging.


Author

RE: Reading a config file in C


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-03-10 20:48
Only taken a quick look at it and off the top of my head I'd say that I see no memset(temp_buf, NULL, 100); anywhere.


Author

RE: Reading a config file in C


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-03-10 21:39
COM wrote:
Only taken a quick look at it and off the top of my head I'd say that I see no memset(temp_buf, NULL, 100); anywhere.


Thanks for the reply, and good call I forgot to put that in there :angry:. Unfortunately the problem is still present but I added memset(temp_buf, '\0', 100); at the end of the file reading while() loop. (http://pastebin.c. . .)


Author

RE: Reading a config file in C


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-03-10 22:04
Well, you could try to copy the stuff into the struct which you've passed instead of into usr_data so that you don't just assign a pointer to something probably reused that only exists in the function anyhow.


Author

RE: Reading a config file in C

spyware
Member



Posts: 4192
Location: The Netherlands
Joined: 14.04.07
Rank:
God
Warn Level: 90
Posted on 09-03-10 22:23
Wild shot in the dark here, but maybe you need to trim your input.



img507.imageshack.us/img507/3580/spynewsig3il1.png
"The chowner of property." - Zeph
[small]
Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term.
- Carl Sagan
“Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor?” - Ebert
[/s
http://bitsofspy.net
Author

RE: Reading a config file in C


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-03-10 22:47
spyware wrote:
Wild shot in the dark here, but maybe you need to trim your input.

Probably not, but even if he does, he will need to copy the contents from usr_data instead of doing what he does which is just to assign a pointer. Assigning just a pointer to something that's reused will fuck him over, especially when it's a pointer to a local variable in a separate function. Even if it would work in one instance it's a very bad habit to get in to. Heck, I'm surprised he didn't get a warning about that shit.


Author

RE: Reading a config file in C


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-03-10 23:30
Thanks for the help Grin I got it working now.

http://pastebin.c. . .

Thanks again.