Bug Summary

File:src/sbin/isakmpd/vendor.c
Warning:line 48, column 32
Result of 'calloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'u_int8_t'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name vendor.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sbin/isakmpd/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/sbin/isakmpd -I . -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/sbin/isakmpd/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/sbin/isakmpd/vendor.c
1/* $OpenBSD: vendor.c,v 1.6 2017/11/08 13:33:49 patrick Exp $ */
2/*
3 * Copyright (c) 2006 Hans-Joerg Hoexer <hshoexer@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <sys/types.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include "exchange.h"
23#include "hash.h"
24#include "log.h"
25#include "message.h"
26#include "vendor.h"
27
28static struct vendor_cap openbsd_vendor_cap[] = {
29 { "OpenBSD-6.3", NULL((void *)0), 0 },
30};
31
32#define NUMVIDS(sizeof openbsd_vendor_cap / sizeof openbsd_vendor_cap[0]) (sizeof openbsd_vendor_cap / sizeof openbsd_vendor_cap[0])
33
34static int
35setup_vendor_hashes(void)
36{
37 struct hash *hash;
38 int i, n = NUMVIDS(sizeof openbsd_vendor_cap / sizeof openbsd_vendor_cap[0]);
39
40 hash = hash_get(HASH_MD5);
41 if (!hash) {
42 log_print("setup_vendor_hashes: could not find MD5 hash");
43 return -1;
44 }
45
46 for (i = 0; i < n; i++) {
47 openbsd_vendor_cap[i].hashsize = hash->hashsize;
48 openbsd_vendor_cap[i].hash = calloc(hash->hashsize,
Result of 'calloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'u_int8_t'
49 sizeof(u_int8_t));
50 if (openbsd_vendor_cap[i].hash == NULL((void *)0)) {
51 log_error("setup_vendor_hashes: calloc failed");
52 goto errout;
53 }
54
55 hash->Init(hash->ctx);
56 hash->Update(hash->ctx,
57 (unsigned char *)openbsd_vendor_cap[i].text,
58 strlen(openbsd_vendor_cap[i].text));
59 hash->Final(openbsd_vendor_cap[i].hash, hash->ctx);
60
61 LOG_DBG((LOG_EXCHANGE, 50, "setup_vendor_hashes: "log_debug (LOG_EXCHANGE, 50, "setup_vendor_hashes: " "MD5(\"%s\") (%lu bytes)"
, openbsd_vendor_cap[i].text, (unsigned long)hash->hashsize
)
62 "MD5(\"%s\") (%lu bytes)", openbsd_vendor_cap[i].text,log_debug (LOG_EXCHANGE, 50, "setup_vendor_hashes: " "MD5(\"%s\") (%lu bytes)"
, openbsd_vendor_cap[i].text, (unsigned long)hash->hashsize
)
63 (unsigned long)hash->hashsize))log_debug (LOG_EXCHANGE, 50, "setup_vendor_hashes: " "MD5(\"%s\") (%lu bytes)"
, openbsd_vendor_cap[i].text, (unsigned long)hash->hashsize
)
;
64 LOG_DBG_BUF((LOG_EXCHANGE, 50, "setup_vendor_hashes",log_debug_buf (LOG_EXCHANGE, 50, "setup_vendor_hashes", openbsd_vendor_cap
[i].hash, hash->hashsize)
65 openbsd_vendor_cap[i].hash, hash->hashsize))log_debug_buf (LOG_EXCHANGE, 50, "setup_vendor_hashes", openbsd_vendor_cap
[i].hash, hash->hashsize)
;
66 }
67 return 0;
68
69errout:
70 for (i = 0; i < n; i++)
71 free(openbsd_vendor_cap[i].hash);
72 return -1;
73}
74
75void
76vendor_init(void)
77{
78 setup_vendor_hashes();
79}
80
81int
82add_vendor_openbsd(struct message *msg)
83{
84 u_int8_t *buf;
85 size_t buflen;
86 int i, n = NUMVIDS(sizeof openbsd_vendor_cap / sizeof openbsd_vendor_cap[0]);
87
88 for (i = 0; i < n; i++) {
89 buflen = openbsd_vendor_cap[i].hashsize + ISAKMP_GEN_SZ4;
90 if ((buf = calloc(buflen, sizeof(char))) == NULL((void *)0)) {
91 log_error("add_vendor_payload: calloc(%lu) failed",
92 (unsigned long)buflen);
93 return -1;
94 }
95
96 SET_ISAKMP_GEN_LENGTH(buf, buflen)field_set_num (isakmp_gen_fld + 2, buf, buflen);
97 memcpy(buf + ISAKMP_VENDOR_ID_OFF4, openbsd_vendor_cap[i].hash,
98 openbsd_vendor_cap[i].hashsize);
99 if (message_add_payload(msg, ISAKMP_PAYLOAD_VENDOR13, buf,
100 buflen, 1)) {
101 free(buf);
102 return -1;
103 }
104 }
105
106 return 0;
107}
108
109void
110check_vendor_openbsd(struct message *msg, struct payload *p)
111{
112 u_int8_t *pbuf = p->p;
113 ssize_t vlen;
114 int i, n = NUMVIDS(sizeof openbsd_vendor_cap / sizeof openbsd_vendor_cap[0]);
115
116 if (msg->exchange->flags & EXCHANGE_FLAG_OPENBSD0x0200) {
117 p->flags |= PL_MARK1;
118 return;
119 }
120
121 vlen = GET_ISAKMP_GEN_LENGTH(pbuf)field_get_num (isakmp_gen_fld + 2, pbuf) - ISAKMP_GEN_SZ4;
122
123 for (i = 0; i < n; i++) {
124 if (vlen != openbsd_vendor_cap[i].hashsize) {
125 LOG_DBG((LOG_EXCHANGE, 90,log_debug (LOG_EXCHANGE, 90, "check_vendor_openbsd: bad size %lu != %lu"
, (unsigned long)vlen, (unsigned long)openbsd_vendor_cap[i].hashsize
)
126 "check_vendor_openbsd: bad size %lu != %lu",log_debug (LOG_EXCHANGE, 90, "check_vendor_openbsd: bad size %lu != %lu"
, (unsigned long)vlen, (unsigned long)openbsd_vendor_cap[i].hashsize
)
127 (unsigned long)vlen,log_debug (LOG_EXCHANGE, 90, "check_vendor_openbsd: bad size %lu != %lu"
, (unsigned long)vlen, (unsigned long)openbsd_vendor_cap[i].hashsize
)
128 (unsigned long)openbsd_vendor_cap[i].hashsize))log_debug (LOG_EXCHANGE, 90, "check_vendor_openbsd: bad size %lu != %lu"
, (unsigned long)vlen, (unsigned long)openbsd_vendor_cap[i].hashsize
)
;
129 continue;
130 }
131 if (memcmp(openbsd_vendor_cap[i].hash, pbuf + ISAKMP_GEN_SZ4,
132 vlen) == 0) {
133 msg->exchange->flags |= EXCHANGE_FLAG_OPENBSD0x0200;
134 LOG_DBG((LOG_EXCHANGE, 10, "check_vendor_openbsd: "log_debug (LOG_EXCHANGE, 10, "check_vendor_openbsd: " "OpenBSD (%s)"
, openbsd_vendor_cap[i].text)
135 "OpenBSD (%s)", openbsd_vendor_cap[i].text))log_debug (LOG_EXCHANGE, 10, "check_vendor_openbsd: " "OpenBSD (%s)"
, openbsd_vendor_cap[i].text)
;
136 }
137 p->flags |= PL_MARK1;
138 }
139}