@@ -209,6 +209,14 @@ static int TPM2_ParamEnc_XOR(TPM2_AUTH_SESSION *session, TPM2B_AUTH* sessKey,
209209 return BUFFER_E ;
210210 }
211211
212+ /* Validate source key sizes to prevent overrun of source buffers */
213+ if (sessKey -> size > sizeof (sessKey -> buffer )) {
214+ return BUFFER_E ;
215+ }
216+ if (bindKey != NULL && bindKey -> size > sizeof (bindKey -> buffer )) {
217+ return BUFFER_E ;
218+ }
219+
212220 /* Validate key sizes before copy to prevent buffer overflow */
213221 if (sessKey -> size + bindKeySz > sizeof (keyIn .buffer )) {
214222 return BUFFER_E ;
@@ -264,6 +272,14 @@ static int TPM2_ParamDec_XOR(TPM2_AUTH_SESSION *session, TPM2B_AUTH* sessKey,
264272 return BUFFER_E ;
265273 }
266274
275+ /* Validate source key sizes to prevent overrun of source buffers */
276+ if (sessKey -> size > sizeof (sessKey -> buffer )) {
277+ return BUFFER_E ;
278+ }
279+ if (bindKey != NULL && bindKey -> size > sizeof (bindKey -> buffer )) {
280+ return BUFFER_E ;
281+ }
282+
267283 /* Validate key sizes before copy to prevent buffer overflow */
268284 if (sessKey -> size + bindKeySz > sizeof (keyIn .buffer )) {
269285 return BUFFER_E ;
@@ -321,6 +337,14 @@ static int TPM2_ParamEnc_AESCFB(TPM2_AUTH_SESSION *session, TPM2B_AUTH* sessKey,
321337 return BUFFER_E ;
322338 }
323339
340+ /* Validate source key sizes to prevent overrun of source buffers */
341+ if (sessKey -> size > sizeof (sessKey -> buffer )) {
342+ return BUFFER_E ;
343+ }
344+ if (bindKey != NULL && bindKey -> size > sizeof (bindKey -> buffer )) {
345+ return BUFFER_E ;
346+ }
347+
324348 /* Validate key sizes before copy to prevent buffer overflow */
325349 if (sessKey -> size + bindKeySz > sizeof (keyIn .buffer )) {
326350 return BUFFER_E ;
@@ -387,6 +411,14 @@ static int TPM2_ParamDec_AESCFB(TPM2_AUTH_SESSION *session, TPM2B_AUTH* sessKey,
387411 return BUFFER_E ;
388412 }
389413
414+ /* Validate source key sizes to prevent overrun of source buffers */
415+ if (sessKey -> size > sizeof (sessKey -> buffer )) {
416+ return BUFFER_E ;
417+ }
418+ if (bindKey != NULL && bindKey -> size > sizeof (bindKey -> buffer )) {
419+ return BUFFER_E ;
420+ }
421+
390422 /* Validate key sizes before copy to prevent buffer overflow */
391423 if (sessKey -> size + bindKeySz > sizeof (keyIn .buffer )) {
392424 return BUFFER_E ;
0 commit comments