Changeset 869e63f


Ignore:
Timestamp:
04/24/14 19:26:47 (17 months ago)
Author:
Mathias Panzenböck <grosser.meister.morti@…>
Branches:
master, enter/10, releng/10.0.2, releng/10.0.3, releng/10.1, releng/10.1.1, releng/10.1.2, releng/10.2, stable/10
Children:
ec454bd
Parents:
ed44f16
Message:

fix potential buffer overflow in SYSTEM::hostname

gethostname() may cause an error or it might need more space than any given static buffer provides. In both cases the data in the buffer might not be null terminated!

Also String() uses fromAscii(). While I guess this should be ok for host names I think it is always better to use fromLocal8Bit(). I think the user name might not be 7-bit ASCII.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lumina/lumina-desktop/Globals.h

    r214f3d5 r869e63f  
    1919public: 
    2020        //Current Username 
    21         static QString user(){ return QString(getlogin()); } 
     21        static QString user(){ return QString::fromLocal8Bit(getlogin()); } 
    2222        //Current Hostname 
    2323        static QString hostname(){  
    24           char name[50]; 
    25           gethostname(name,sizeof(name)); 
    26           return QString(name); 
     24          char name[64]; 
     25          int count = gethostname(name,sizeof(name)); 
     26          if (count < 0) { 
     27            return QString::null; 
     28          } 
     29          return QString::fromLocal8Bit(name,count); 
    2730        } 
    2831        //Shutdown the system 
Note: See TracChangeset for help on using the changeset viewer.