tss2/sast.diff
Štěpán Horáček 264678fced Fix bugs found by SAST
Resolves: RHEL-62754

Signed-off-by: Štěpán Horáček <shoracek@redhat.com>
2025-01-22 16:07:13 +01:00

66 lines
2.4 KiB
Diff

diff --git a/utils/imalib.c b/utils/imalib.c
index 1910dcc..8d40fd2 100644
--- a/utils/imalib.c
+++ b/utils/imalib.c
@@ -2164,7 +2164,7 @@ static uint32_t IMA_ParseXATTRNAMES(ImaTemplateData *imaTemplateData,
imaTemplateData->imaTemplateXattrs.xattrNamesCount++;
for (i = 1 ;
- i < sizeof(((ImaTemplateData *)NULL)->imaTemplateXattrs.xattrNamesPtr) ; i++) {
+ i < (sizeof(((ImaTemplateData *)NULL)->imaTemplateXattrs.xattrNamesPtr)) / sizeof(char *) ; i++) {
/* the | is a separator character */
imaTemplateData->imaTemplateXattrs.xattrNamesPtr[i] =
strchr(imaTemplateData->imaTemplateXattrs.xattrNamesPtr[i-1], '|');
diff --git a/utils/policymaker.c b/utils/policymaker.c
index 7290ed7..f9c7212 100644
--- a/utils/policymaker.c
+++ b/utils/policymaker.c
@@ -185,10 +185,10 @@ int main(int argc, char *argv[])
}
if (rc == 0) {
sizeInBytes = TSS_GetDigestSize(digest.hashAlg);
+ memset((uint8_t *)&digest.digest, 0, sizeInBytes);
/* startauthsession sets session digest to zero */
if (!nz) {
startSizeInBytes = sizeInBytes;
- memset((uint8_t *)&digest.digest, 0, sizeInBytes);
}
else { /* nz TRUE, start with empty buffer */
startSizeInBytes = 0;
diff --git a/utils/tpmproxy.c b/utils/tpmproxy.c
index 1948121..15f980a 100644
--- a/utils/tpmproxy.c
+++ b/utils/tpmproxy.c
@@ -556,7 +556,7 @@ TPM_RC socketWrite(SOCKET_FD accept_fd, /* read/write file descriptor */
}
}
while ((rc == 0) && (buffer_length > 0)) {
- nwritten = send(accept_fd, buffer, (int)buffer_length, 0);
+ nwritten = send(accept_fd, buffer, buffer_length, 0);
if ((nwritten == SOCKET_ERROR) ||
(nwritten < 0)) {
printf("socketWrite: Error, send()\n");
diff --git a/utils/tsssocket.c b/utils/tsssocket.c
index 24cc5fd..992f8c2 100644
--- a/utils/tsssocket.c
+++ b/utils/tsssocket.c
@@ -594,15 +594,15 @@ static uint32_t TSS_Socket_ReceiveBytes(TSS_SOCKET_FD sock_fd,
uint8_t *buffer,
uint32_t nbytes)
{
- int nread = 0;
- int nleft = 0;
+ ssize_t nread = 0;
+ size_t nleft = 0;
nleft = nbytes;
while (nleft > 0) {
#ifdef TPM_POSIX
nread = read(sock_fd, buffer, nleft);
if (nread < 0) { /* error */
- if (tssVerbose) printf("TSS_Socket_ReceiveBytes: read error %d\n", nread);
+ if (tssVerbose) printf("TSS_Socket_ReceiveBytes: read error %d\n", errno);
return TSS_RC_BAD_CONNECTION;
}
#endif