Tim,

Thank you for reporting this.  Your patch has been reviewed and committed to 
www.tianocore.org<http://www.tianocore.org>.

Sincerely,
Daryl McDaniel

"Software is like entropy.
 It is difficult to grasp, weighs nothing, and obeys the second law of 
thermodynamics;
 i.e. it always increases."
-- Norman R. Augustine

________________________________
From: Tim Lewis [mailto:[email protected]]
Sent: Wednesday, July 18, 2012 10:47 AM
To: [email protected]
Subject: [edk2] WideTtyCvt problem

The current code will hang (or generate an exception under Nt32Pkg) if an 
illegal character is actually returned from mbrtowc. In this case, numB becomes 
-1. In this case i, n and buf are decremented.

I can duplicate with this line:

puts("you've\r");

The ' character does not translate.


I added a single line (numB = 1) in this case and verified that it fixes the 
issue:

WideTtyCvt( CHAR16 *dest, const char *buf, ssize_t n, mbstate_t *Cs)
{
  ssize_t i     = 0;
  int     numB  = 0;
  wchar_t wc[2];

  while (n > 0) {
    numB = (int)mbrtowc (wc, buf, MIN(MB_LEN_MAX,n), Cs);
    if (numB == 0) {
      break;
    }

    if (numB < 0) {                   // if an illegal character replace it.
      wc[0] = BLOCKELEMENT_LIGHT_SHADE;
      numB = 1;
    }
    if (wc[0] == L'\n') {
      *dest++ = L'\r';
      ++i;
    }
    *dest++ = (CHAR16)wc[0];
    i += numB;
    n -= numB;
    buf += numB;
  }
  *dest = 0;
  return i;
}


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to