Previous Thread
Next Thread
Print Thread
mktemp is dangerous! #30948 06/30/07 03:35 AM
Joined: May 2000
Posts: 275
XulChris Offline OP
Senior Member
OP Offline
Senior Member
Joined: May 2000
Posts: 275
From the man page:
Never use mktemp().

From the compile:
obj/sdl/mess/libocore.a(sdlmess.o): In function `osd_get_temp_filename':
sdlmess.c:(.text+0x93): warning: the use of `mktemp' is dangerous, better use `mkstemp'

That message repeats three times every time I type make. And I type make about 400 times a day! frown


Re: mktemp is dangerous! [Re: XulChris] #30957 06/30/07 07:07 AM
Joined: Mar 2001
Posts: 16,390
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,390
Yes, I know. But that never gets called in normal operation of MAME/MESS, and mkstemp() has completely different semantics that are unusable for what MESS wants.

ETA: It turns out after some Googling that mkdtemp() *is* a secure compatible replacement - someone needs to fix the stupid linker scold (someone already filed a bug against GCC about it, which is handy). The man page claims all the BSDs have it - judge, would you mind checking FreeBSD for me? I can check OS X.

Last edited by R. Belmont; 06/30/07 07:11 AM.
Re: mktemp is dangerous! [Re: R. Belmont] #30971 06/30/07 05:15 PM
Joined: Apr 2004
Posts: 1,554
J
judge Offline
Very Senior Member
Offline
Very Senior Member
J
Joined: Apr 2004
Posts: 1,554

Re: mktemp is dangerous! [Re: judge] #30981 06/30/07 10:48 PM
Joined: May 2000
Posts: 275
XulChris Offline OP
Senior Member
OP Offline
Senior Member
Joined: May 2000
Posts: 275
Sounds like mkdtemp() actually creates a directory, and all we want is a file name correct? What about using tempnam()?



Re: mktemp is dangerous! [Re: XulChris] #30982 06/30/07 10:50 PM
Joined: Mar 2001
Posts: 16,390
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,390
No, we need the exact semantics of mktemp/mkdtemp. It no longer warns with current SVN but if you insist on extending this topic I can very easily put mktemp back.

Last edited by R. Belmont; 06/30/07 10:51 PM.
Re: mktemp is dangerous! [Re: R. Belmont] #30984 06/30/07 11:02 PM
Joined: May 2000
Posts: 275
XulChris Offline OP
Senior Member
OP Offline
Senior Member
Joined: May 2000
Posts: 275
Originally Posted By R. Belmont
No, we need the exact semantics of mktemp/mkdtemp. It no longer warns with current SVN but if you insist on extending this topic I can very easily put mktemp back.


SVN is not fixed here.

My mistake then I guess, I read the man pages and it read like mkdtemp creates a directory which I assumed was not what we wanted to do. I thought the function was only supposed to return a file name, and not actually create any files/dirs. I apologize if I'm mistaken, I'm only trying to be helpful.

Re: mktemp is dangerous! [Re: XulChris] #30986 07/01/07 12:26 AM
Joined: Mar 2001
Posts: 16,390
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,390
Meh, you're right, there is no actual equivalent for mktemp() that isn't marked DO NOT EVER USE. I'll just do what the baseline code does and generate "/tmp/[passed in name]" then do a delete on that name. It's probably even more insecure than mktemp, but it shuts up the linker and that's what really counts.

Re: mktemp is dangerous! [Re: R. Belmont] #30987 07/01/07 12:27 AM
Joined: May 2000
Posts: 275
XulChris Offline OP
Senior Member
OP Offline
Senior Member
Joined: May 2000
Posts: 275
Yeah, I was just going to say the same thing. I tried using tempnam() and gcc complains about that! Stupid gcc. I agree, the best thing here is to just do it by hand like the windows side does. smile

Re: mktemp is dangerous! [Re: XulChris] #30994 07/01/07 05:29 AM
Joined: Sep 2001
Posts: 534
F
Firewave Offline
Senior Member
Offline
Senior Member
F
Joined: Sep 2001
Posts: 534
If we would change all deprecated functions VS2003+ is complaining about...


Moderated by  R. Belmont 

Who's Online Now
1 registered members (Pernod), 179 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
ShoutChat Box
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,722
Posts114,633
Members4,873
Most Online510
Aug 26th, 2019
Powered by UBB.threads™ PHP Forum Software 7.7.3