Coverage Report

Created: 2026-01-16 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ibmswtpm2/src/IoBuffers.c
Line
Count
Source
1
/********************************************************************************/
2
/*                    */
3
/*          I/O Buffers           */
4
/*           Written by Ken Goldman       */
5
/*           IBM Thomas J. Watson Research Center     */
6
/*            $Id: IoBuffers.c 1311 2018-08-23 21:39:29Z kgoldman $   */
7
/*                    */
8
/*  Licenses and Notices              */
9
/*                    */
10
/*  1. Copyright Licenses:              */
11
/*                    */
12
/*  - Trusted Computing Group (TCG) grants to the user of the source code in  */
13
/*    this specification (the "Source Code") a worldwide, irrevocable,    */
14
/*    nonexclusive, royalty free, copyright license to reproduce, create  */
15
/*    derivative works, distribute, display and perform the Source Code and */
16
/*    derivative works thereof, and to grant others the rights granted herein.  */
17
/*                    */
18
/*  - The TCG grants to the user of the other parts of the specification  */
19
/*    (other than the Source Code) the rights to reproduce, distribute,   */
20
/*    display, and perform the specification solely for the purpose of    */
21
/*    developing products based on such documents.        */
22
/*                    */
23
/*  2. Source Code Distribution Conditions:         */
24
/*                    */
25
/*  - Redistributions of Source Code must retain the above copyright licenses,  */
26
/*    this list of conditions and the following disclaimers.      */
27
/*                    */
28
/*  - Redistributions in binary form must reproduce the above copyright   */
29
/*    licenses, this list of conditions and the following disclaimers in the  */
30
/*    documentation and/or other materials provided with the distribution.  */
31
/*                    */
32
/*  3. Disclaimers:               */
33
/*                    */
34
/*  - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */
35
/*  LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */
36
/*  RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */
37
/*  THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE.   */
38
/*  Contact TCG Administration (admin@trustedcomputinggroup.org) for    */
39
/*  information on specification licensing rights available through TCG   */
40
/*  membership agreements.              */
41
/*                    */
42
/*  - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED   */
43
/*    WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR   */
44
/*    FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR    */
45
/*    NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY    */
46
/*    OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.   */
47
/*                    */
48
/*  - Without limitation, TCG and its members and licensors disclaim all  */
49
/*    liability, including liability for infringement of any proprietary  */
50
/*    rights, relating to use of information in this specification and to the */
51
/*    implementation of this specification, and TCG disclaims all liability for */
52
/*    cost of procurement of substitute goods or services, lost profits, loss   */
53
/*    of use, loss of data or any incidental, consequential, direct, indirect,  */
54
/*    or special damages, whether under contract, tort, warranty or otherwise,  */
55
/*    arising in any way out of use or reliance upon this specification or any  */
56
/*    information herein.             */
57
/*                    */
58
/*  (c) Copyright IBM Corp. and others, 2016 - 2018       */
59
/*                    */
60
/********************************************************************************/
61
62
/* 9.7  IoBuffers.c */
63
/* 9.7.1  Includes and Data Definitions */
64
/* This definition allows this module to see the values that are private to this module but kept in
65
   Global.c for ease of state migration. */
66
#define IO_BUFFER_C
67
#include "Tpm.h"
68
#include "IoBuffers_fp.h"
69
/* 9.7.2  Buffers and Functions */
70
/* These buffers are set aside to hold command and response values. In this implementation, it is
71
   not guaranteed that the code will stop accessing the s_actionInputBuffer before starting to put
72
   values in the s_actionOutputBuffer so different buffers are required. */
73
/*     9.7.2.1 MemoryIoBufferAllocationReset() */
74
/*     This function is used to reset the allocation of buffers. */
75
void
76
MemoryIoBufferAllocationReset(
77
            void
78
            )
79
1.04k
{
80
1.04k
    s_actionIoAllocation = 0;
81
1.04k
}
82
/* 9.7.2.2  MemoryIoBufferZero() */
83
/* Function zeros the action I/O buffer at the end of a command. Calling this is not mandatory for
84
   proper functionality. */
85
void
86
MemoryIoBufferZero(
87
       void
88
       )
89
1.04k
{
90
1.04k
    memset(s_actionIoBuffer, 0, s_actionIoAllocation);
91
1.04k
}
92
/* 9.7.2.3  MemoryGetInBuffer() */
93
/* This function returns the address of the buffer into which the command parameters will be
94
   unmarshaled in preparation for calling the command actions. */
95
BYTE *
96
MemoryGetInBuffer(
97
      UINT32           size           // Size, in bytes, required for the input
98
      // unmarshaling
99
      )
100
1.04k
{
101
1.04k
    pAssert(size <= sizeof(s_actionIoBuffer));
102
    // In this implementation, a static buffer is set aside for the command action
103
    // buffers. The buffer is shared between input and output. This is because
104
    // there is no need to allocate for the worst case input and worst case output
105
    // at the same time.
106
    // Round size up
107
3.14k
#define UoM  (sizeof(s_actionIoBuffer[0]))
108
1.04k
    size = (size + (UoM - 1)) & (UINT32_MAX - (UoM - 1));
109
1.04k
    memset(s_actionIoBuffer, 0, size);
110
1.04k
    s_actionIoAllocation = size;
111
1.04k
    return (BYTE *)&s_actionIoBuffer[0];
112
1.04k
}
113
/* 9.7.2.4  MemoryGetOutBuffer() */
114
/* This function returns the address of the buffer into which the command action code places its
115
   output values. */
116
BYTE *
117
MemoryGetOutBuffer(
118
       UINT32           size           // required size of the buffer
119
       )
120
1.04k
{
121
1.04k
    BYTE        *retVal = (BYTE *)(&s_actionIoBuffer[s_actionIoAllocation / UoM]);
122
1.04k
    pAssert((size + s_actionIoAllocation) < (sizeof(s_actionIoBuffer)));
123
    // In this implementation, a static buffer is set aside for the command action
124
    // output buffer.
125
1.04k
    memset(retVal, 0, size);
126
1.04k
    s_actionIoAllocation += size;
127
1.04k
    return retVal;
128
1.04k
}
129
/* 9.7.2.5  IsLabelProperlyFormatted() */
130
/* This function checks that a label is a null-terminated string. */
131
/* NOTE:  this function is here because there was no better place for it. */
132
/* Return Value Meaning */
133
/* FALSE  string is not null terminated */
134
/* TRUE string is null terminated */
135
136
BOOL
137
IsLabelProperlyFormatted(
138
       TPM2B           *x
139
       )
140
0
{
141
0
    return (((x)->size == 0) || ((x)->buffer[(x)->size - 1] == 0));
142
0
}
143
144
145