Skip to content

Commit 9767c5f

Browse files
committed
handle failure in encrypt_rfbdes() in callers
1 parent e64fa92 commit 9767c5f

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

include/rfb/rfbproto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ typedef union {
15571557
extern int rfbEncryptAndStorePasswd(char *passwd, char *fname);
15581558
extern char *rfbDecryptPasswdFromFile(char *fname);
15591559
extern void rfbRandomBytes(unsigned char *bytes);
1560-
extern void rfbEncryptBytes(unsigned char *bytes, char *passwd);
1560+
extern rfbBool rfbEncryptBytes(unsigned char *bytes, char *passwd);
15611561

15621562

15631563
#endif

src/common/vncauth.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ rfbEncryptAndStorePasswd(char *passwd, char *fname)
102102

103103
/* Do encryption in-place - this way we overwrite our copy of the plaintext
104104
password */
105-
encrypt_rfbdes(encryptedPasswd, &out_len, fixedkey, encryptedPasswd, sizeof(encryptedPasswd));
105+
if (encrypt_rfbdes(encryptedPasswd, &out_len, fixedkey, encryptedPasswd, sizeof(encryptedPasswd)) == 0) {
106+
fclose(fp);
107+
return 1;
108+
}
106109

107110
for (i = 0; i < 8; i++) {
108111
putc(encryptedPasswd[i], fp);
@@ -177,10 +180,11 @@ rfbRandomBytes(unsigned char *bytes)
177180
#endif
178181

179182
/*
180-
* Encrypt CHALLENGESIZE bytes in memory using a password.
183+
* Encrypt CHALLENGESIZE bytes in memory using a password. Returns TRUE
184+
* if successful, FALSE if the encryption failed.
181185
*/
182186

183-
void
187+
rfbBool
184188
rfbEncryptBytes(unsigned char *bytes, char *passwd)
185189
{
186190
unsigned char key[8];
@@ -197,19 +201,24 @@ rfbEncryptBytes(unsigned char *bytes, char *passwd)
197201
}
198202
}
199203

200-
encrypt_rfbdes(bytes, &out_len, key, bytes, CHALLENGESIZE);
204+
return encrypt_rfbdes(bytes, &out_len, key, bytes, CHALLENGESIZE) == 0;
201205
}
202206

203-
void
207+
rfbBool
204208
rfbEncryptBytes2(unsigned char *where, const int length, unsigned char *key) {
205209
int i, j, out_len;
206210
for (i = 0; i< 8; i++)
207211
where[i] ^= key[i];
208-
encrypt_rfbdes(where, &out_len, key, where, 8);
212+
if (encrypt_rfbdes(where, &out_len, key, where, 8) == 0) {
213+
return TRUE;
214+
}
209215
for (i = 8; i < length; i += 8) {
210216
for (j = 0; j < 8; j++) {
211217
where[i + j] ^= where[i + j - 8];
212218
}
213-
encrypt_rfbdes(where + i, &out_len, key, where + i, 8);
219+
if (encrypt_rfbdes(where + i, &out_len, key, where + i, 8) == 0) {
220+
return TRUE;
221+
}
214222
}
223+
return FALSE;
215224
}

src/libvncclient/rfbclient.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ rfbBool ConnectToRFBRepeater(rfbClient* client,const char *repeaterHost, int rep
404404
return TRUE;
405405
}
406406

407-
extern void rfbClientEncryptBytes(unsigned char* bytes, char* passwd);
408-
extern void rfbClientEncryptBytes2(unsigned char *where, const int length, unsigned char *key);
407+
extern int rfbClientEncryptBytes(unsigned char* bytes, char* passwd);
408+
extern int rfbClientEncryptBytes2(unsigned char *where, const int length, unsigned char *key);
409409

410410
static void
411411
ReadReason(rfbClient* client)
@@ -585,7 +585,10 @@ HandleVncAuth(rfbClient *client)
585585
passwd[8] = '\0';
586586
}
587587

588-
rfbClientEncryptBytes(challenge, passwd);
588+
if (rfbClientEncryptBytes(challenge, passwd) != 0) {
589+
rfbClientLog("Encryption failed\n");
590+
return FALSE;
591+
}
589592

590593
/* Lose the password from memory */
591594
for (i = strlen(passwd); i >= 0; i--) {
@@ -733,8 +736,14 @@ HandleUltraMSLogonIIAuth(rfbClient *client)
733736
strncpy((char *)password, cred->userCredential.password, sizeof(password)-1);
734737
FreeUserCredential(cred);
735738

736-
rfbClientEncryptBytes2(username, sizeof(username), (unsigned char *)key);
737-
rfbClientEncryptBytes2(password, sizeof(password), (unsigned char *)key);
739+
if (rfbClientEncryptBytes2(username, sizeof(username), (unsigned char *)key) != 0) {
740+
rfbClientLog("Encrypting username failed\n");
741+
return FALSE;
742+
}
743+
if (rfbClientEncryptBytes2(password, sizeof(password), (unsigned char *)key) != 0) {
744+
rfbClientLog("Encrypting password failed\n");
745+
return FALSE;
746+
}
738747

739748
if (!WriteToRFBServer(client, (char *)pub, sizeof(pub))) return FALSE;
740749
if (!WriteToRFBServer(client, (char *)username, sizeof(username))) return FALSE;
@@ -789,8 +798,14 @@ HandleMSLogonAuth(rfbClient *client)
789798
pub = rfbClientSwap64IfLE(pub);
790799
key = rfbClientSwap64IfLE(key);
791800

792-
rfbClientEncryptBytes2(username, sizeof(username), (unsigned char *)&key);
793-
rfbClientEncryptBytes2(password, sizeof(password), (unsigned char *)&key);
801+
if (rfbClientEncryptBytes2(username, sizeof(username), (unsigned char *)key) != 0) {
802+
rfbClientLog("Encrypting username failed\n");
803+
return FALSE;
804+
}
805+
if (rfbClientEncryptBytes2(password, sizeof(password), (unsigned char *)key) != 0) {
806+
rfbClientLog("Encrypting password failed\n");
807+
return FALSE;
808+
}
794809

795810
if (!WriteToRFBServer(client, (char *)&pub, 8)) return FALSE;
796811
if (!WriteToRFBServer(client, (char *)username, sizeof(username))) return FALSE;

src/libvncserver/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,11 @@ static rfbBool rfbDefaultPasswordCheck(rfbClientPtr cl,const char* response,int
798798
return(FALSE);
799799
}
800800

801-
rfbEncryptBytes(cl->authChallenge, passwd);
801+
if (!rfbEncryptBytes(cl->authChallenge, passwd)) {
802+
rfbErr("Encryption failed\n");
803+
free(passwd);
804+
return(FALSE);
805+
}
802806

803807
/* Lose the password from memory */
804808
for (i = strlen(passwd); i >= 0; i--) {
@@ -826,7 +830,10 @@ rfbBool rfbCheckPasswordByList(rfbClientPtr cl,const char* response,int len)
826830
for(passwds=(char**)cl->screen->authPasswdData;*passwds;passwds++,i++) {
827831
uint8_t auth_tmp[CHALLENGESIZE];
828832
memcpy((char *)auth_tmp, (char *)cl->authChallenge, CHALLENGESIZE);
829-
rfbEncryptBytes(auth_tmp, *passwds);
833+
if (!rfbEncryptBytes(auth_tmp, *passwds)) {
834+
rfbErr("Encryption failed\n");
835+
return(FALSE);
836+
}
830837

831838
if (memcmp(auth_tmp, response, len) == 0) {
832839
if(i>=cl->screen->authPasswdFirstViewOnly)

0 commit comments

Comments
 (0)