• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stefanberger / swtpm / #2961

01 May 2026 01:51AM UTC coverage: 73.207% (-0.5%) from 73.671%
#2961

push

travis-ci

web-flow
Merge 2ac6ba54c into 208a85242

2 of 3 new or added lines in 1 file covered. (66.67%)

1889 existing lines in 28 files now uncovered.

8052 of 10999 relevant lines covered (73.21%)

13564.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.02
/src/swtpm/swtpm_debug.c
1
/********************************************************************************/
2
/*                                                                              */
3
/*                         TPM Debug Utilities                                  */
4
/*                           Written by Ken Goldman                             */
5
/*                     IBM Thomas J. Watson Research Center                     */
6
/*            $Id: tpm_debug.c 4179 2010-11-10 20:10:24Z kgoldman $             */
7
/*                                                                              */
8
/* (c) Copyright IBM Corporation 2006, 2010.                                        */
9
/*                                                                                */
10
/* All rights reserved.                                                                */
11
/*                                                                                 */
12
/* Redistribution and use in source and binary forms, with or without                */
13
/* modification, are permitted provided that the following conditions are        */
14
/* met:                                                                                */
15
/*                                                                                 */
16
/* Redistributions of source code must retain the above copyright notice,        */
17
/* this list of conditions and the following disclaimer.                        */
18
/*                                                                                 */
19
/* Redistributions in binary form must reproduce the above copyright                */
20
/* notice, this list of conditions and the following disclaimer in the                */
21
/* documentation and/or other materials provided with the distribution.                */
22
/*                                                                                 */
23
/* Neither the names of the IBM Corporation nor the names of its                */
24
/* contributors may be used to endorse or promote products derived from                */
25
/* this software without specific prior written permission.                        */
26
/*                                                                                 */
27
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS                */
28
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT                */
29
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR        */
30
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT                */
31
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,        */
32
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT                */
33
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,        */
34
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY        */
35
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT                */
36
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE        */
37
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                */
38
/********************************************************************************/
39

40
#include <config.h>
41

42
#define _GNU_SOURCE
43
#include <stdlib.h>
44
#include <stdio.h>
45
#include <stdint.h>
46
#include <string.h>
47
#include <stdarg.h>
48

49
#include "swtpm_debug.h"
50
#include "logging.h"
51

52
/*
53
 * SWTPM_AppendPrintf() print and append to buffer
54
 *
55
 * @buffer: pointer to existing buffer or pointer to NULL to start a new buffer
56
 * @fmt: typical printf fmt
57
 * @...: varagr printf parameters
58
 *
59
 */
60
static int SWTPM_AppendPrintf(char **buffer, const char *fmt, ...)
386,867✔
61
{
62
    va_list ap;
386,867✔
63
    int n, len = 0;
386,867✔
64
    char *dest = NULL, *nbuffer;
386,867✔
65

66
    va_start(ap, fmt);
386,867✔
67
    n = vasprintf(&dest, fmt, ap);
386,867✔
68
    va_end(ap);
386,867✔
69
    if (n < 0)
386,867✔
70
        return n;
71

72
    if (*buffer)
386,867✔
73
        len = strlen(*buffer);
362,782✔
74

75
    nbuffer = malloc(len + n + 1);
386,867✔
76
    if (!nbuffer) {
386,867✔
UNCOV
77
        free(dest);
×
UNCOV
78
        return -1;
×
79
    }
80
    if (*buffer)
386,867✔
81
        memcpy(nbuffer, *buffer, len);
362,782✔
82
    memcpy(&nbuffer[len], dest, n);
386,867✔
83
    nbuffer[len + n] = 0;
386,867✔
84

85
    free(dest);
386,867✔
86
    free(*buffer);
386,867✔
87
    *buffer = nbuffer;
386,867✔
88

89
    return len + n;
386,867✔
90
}
91

92
/* SWTPM_PrintAll() prints 'string', the length, and then the entire byte array
93
 */
94
void SWTPM_PrintAll(const char *string, const char *indentation,
88,318✔
95
                    const unsigned char* buff, uint32_t length)
96
{
97
    uint32_t i;
88,318✔
98
    int indent;
88,318✔
99
    char *linebuffer = NULL;
88,318✔
100

101
    indent = log_check_string(string);
88,318✔
102
    if (indent < 0)
88,318✔
103
        return;
104

105
    if (buff != NULL) {
5,392✔
106
        logprintf(STDERR_FILENO, "%s length %u\n", string, length);
5,392✔
107

108
        SWTPM_AppendPrintf(&linebuffer, "%s", indentation);
5,392✔
109
        for (i = 0 ; i < length ; i++) {
349,481✔
110
            if (i && !( i % 16 )) {
338,697✔
111
                SWTPM_AppendPrintf(&linebuffer, "\n");
18,693✔
112

113
                logprintfA(STDERR_FILENO, 0, linebuffer);
18,693✔
114

115
                free(linebuffer);
18,693✔
116
                linebuffer = NULL;
18,693✔
117
                SWTPM_AppendPrintf(&linebuffer, "%s", indentation);
18,693✔
118
            }
119

120
            SWTPM_AppendPrintf(&linebuffer, "%.2X ", buff[i]);
338,697✔
121
        }
122
        SWTPM_AppendPrintf(&linebuffer, "\n");
5,392✔
123
        logprintf(STDERR_FILENO, "%s", linebuffer);
5,392✔
124
        free(linebuffer);
5,392✔
125
    }
126
    else {
UNCOV
127
        logprintf(STDERR_FILENO, "%s null\n", string);
×
128
    }
129
    return;
130
}
131

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc