forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Buffer overflow in pspDebugScreenPrintf()

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
bronsky



Joined: 24 Dec 2006
Posts: 12
Location: Paris

PostPosted: Sun Dec 24, 2006 6:02 am    Post subject: Buffer overflow in pspDebugScreenPrintf() Reply with quote

Hello all,

I'm not sure of where to post bug reports, hope i'm at the right place...

I found a buffer overflow problem in the pspDebugScreenPrintf() function. You can observe it by trying to output a string of more than 2048 characters with that function: the end (and possibly all) of the displaying will be totally messy.

I took a look at the file scr_printf.c and seen that pspDebugScreenPrintf() asks vsnprintf() to do the formatting stuff and considers that the return value is the number of characters actually printed, as specified in C89. But in C99, the return value is now the number of characters that WOULD HAVE been printed if the length of the preallocated buffer would have been sufficient. So the pspDebugScreenPrintData() then issues a buffer overflow by considering the size passed in parameter as being the actual size of the buffer.

So I think that it would be better to not use the return value of vsnprintf(), and call pspDebugScreenPrintData() like that:
Code:
(void) pspDebugScreenPrintData(buff, sizeof(buff));

That way the data will just be truncated.

Hope this can help...
Back to top
View user's profile Send private message
bronsky



Joined: 24 Dec 2006
Posts: 12
Location: Paris

PostPosted: Sun Dec 24, 2006 6:07 am    Post subject: Reply with quote

Humm after consideration maybe this will be better:
Code:
(void) pspDebugScreenPrintData(buff, strlen(buff));
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sun Dec 24, 2006 11:36 am    Post subject: Reply with quote

Very true, it probably shouldn't be so stupid to try and print the length of characters it _should_ be, but then again do you really need to print 2048 characters in one run? I'll look at making sure it fixes it though :)
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Sun Dec 24, 2006 7:08 pm    Post subject: Reply with quote

Wow! 2048 chars at a time. Are you printing an encyclopedia? :p
Back to top
View user's profile Send private message
bronsky



Joined: 24 Dec 2006
Posts: 12
Location: Paris

PostPosted: Sun Dec 24, 2006 8:49 pm    Post subject: Reply with quote

Hehe... yeah it's somewhat violent, but it was for debug purpose : I wanted to display in text mode a png file and I put all the stuff in one string instead of doing one printf per line... I don't do such weird things in final code! :)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group