Il primo problema è che non è protetto da thread e il buffer delle stringhe utilizzato non contiene un valore attendibile; Ad esempio, non puoi essere sicuro che il valore che ottieni non vada bene. US-CERT entra nei dettagli.
The results of getlogin() should not be trusted.
The getlogin() function returns a pointer to a string that contains
the name of the user associated with the calling process. The function
is not reentrant, meaning that if it is called from another process,
the contents are not locked out and the value of the string can be
changed by another process. This makes it very risky to use because
the username can be changed by other processes, so the results of the
function cannot be trusted.
US-CERT ha ulteriori dettagli sul problema . Un'alternativa è utilizzare la versione thread-safe getlogin_r () o utilizzare altri meccanismi.
Il secondo problema è che t qui è un difetto noto in SSH che consente agli aggressori per spoofare in modo specifico il risultato di getlogin () :
On platforms relying on getlogin() (mainly the different BSD variants)
malicious users can at least send misleading messages to syslog and
others applications (getlogin() call will return "root").
Rapid7 ha anche altri dettagli .