Patch for variable arguments bug in Tinyfugue (screen corruption)

by David Sexton Aug 5 2010 07:09 PM PST

Most of the modifications that I have made to Tinyfugue's source code have been through a shell account on an old machine running 32-bit RHEL 3.  I've never had a problem compiling and using Tinyfugue unless the changes that I've made have broken the build.  Just today I decided to move everything over to my own computer.  I'm currently running a 64bit build of Ubuntu.  As I was switching over, I decided to run builds of the various branches that I work on (dotnotation, C style block comments, Top status area, Telnet option negotiation, etc).  Everything compiled smoothly, with some additional warnings that weren't present on the older compiler available in RHEL 3.  The big surprise was when I attempted to run the latest build of Tinyfugue that includes my telnet option negotiation patch.  I was shocked that the screen was garbled with input, status, and output areas all overlapping.  Even after exiting Tinyfuge, my Konsole session was not working correctly.

 

Of course, the first that I did was fall back to the unaltered tf-50b8 source code and ran a build.  When the compilation finished, I ran Tinyfugue and saw that the same screen errors were occuring.  I then started debugging Tinyfugue to find out the exact cause of the issue.  After too much time, I finally narrowed it down to the vSprintf function in tfio.c file.  The vSprintf function is passed a va_list.  The va_list is correctly intialized using va_start and torn down using va_end in the function calling vSprintf, so the basic code logic is sound.  The issue is that vSprintf tries to use the va_list after it's been passed to the vsprintf function.  According to the C99 documentation ([ISO/IEC 9899:1999], Section 7.15), the va_list actually is actually in an indeterminate state after returning from the vsprintf function.  So once Tinyfugue tries to use the va_list a second time, it fails (but relatively gracefully).  The failure in this case is just enough to throw the screen functions off, but not enough to crash Tinyfugue.  The solution is to modify vSprintf to use the va_copy macro to make a copy of the va_list, then pass the copy off to the vsprintf function and keep the original copy for internal use.  When work is done on the copied va_list, va_end is called on it.

 

After getting that patch in place, Tinyfugue now works on my 64 bit Ubuntu machine.  I need to patch all of my branches, but I'm also including the patch here seperately so that anyone who wants to can use it.  I'm unsure if this is an issue with new GCC builds or if it is because of the switch from 32bit to 64bit linux.  In either case, the updated code compiles correctly and shows no signs of screen corruption on either system.

 

Continued at Patch for variable arguments bug in Tinyfugue (screen-corruption) (Cont)

 

fix64bit_va.patch (1.43 kb)

Tags: , ,

Patches | Tinyfugue

Comments

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

Name: David Sexton

Currenty City: Portland, OR

I'm a full time programmer (mainly Microsoft stack), just looking for a spot to put stuff that I can't find a better place for.

Month List