Bug Summary

File:src/sbin/wsconsctl/display.c
Warning:line 152, column 6
2nd function call argument is an uninitialized value

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 display.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/wsconsctl/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/sbin/wsconsctl -I . -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/sbin/wsconsctl/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/wsconsctl/display.c
1/* $OpenBSD: display.c,v 1.22 2019/06/28 13:32:46 deraadt Exp $ */
2/* $NetBSD: display.c,v 1.1 1998/12/28 14:01:16 hannken Exp $ */
3
4/*-
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Juergen Hannken-Illjes.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/ioctl.h>
34#include <sys/time.h>
35#include <dev/wscons/wsconsio.h>
36#include <errno(*__errno()).h>
37#include <fcntl.h>
38#include <err.h>
39#include <stdio.h>
40#include <string.h>
41#include "wsconsctl.h"
42
43u_int dpytype;
44u_int width, height, depth, fontwidth, fontheight;
45int focus;
46struct field_pc brightness, contrast, backlight;
47int burnon, burnoff, vblank, kbdact, msact, outact;
48char fontname[WSFONT_NAME_SIZE32];
49struct wsdisplay_emultype emuls;
50struct wsdisplay_screentype screens;
51
52struct field display_field_tab[] = {
53 { "type", &dpytype, FMT_DPYTYPE103, FLG_RDONLY0x0001 },
54 { "width", &width, FMT_UINT1, FLG_RDONLY0x0001 },
55 { "height", &height, FMT_UINT1, FLG_RDONLY0x0001 },
56 { "depth", &depth, FMT_UINT1, FLG_RDONLY0x0001 },
57 { "fontwidth", &fontwidth, FMT_UINT1, FLG_RDONLY0x0001 },
58 { "fontheight", &fontheight, FMT_UINT1, FLG_RDONLY0x0001 },
59 { "emulations", &emuls, FMT_EMUL107, FLG_RDONLY0x0001 },
60 { "screentypes", &screens, FMT_SCREEN108, FLG_RDONLY0x0001 },
61 { "focus", &focus, FMT_INT2, FLG_NORDBACK0x0010 },
62 { "brightness", &brightness, FMT_PC4, FLG_MODIFY0x0008|FLG_INIT0x0400 },
63 { "contrast", &contrast, FMT_PC4, FLG_MODIFY0x0008|FLG_INIT0x0400 },
64 { "backlight", &backlight, FMT_PC4, FLG_MODIFY0x0008|FLG_INIT0x0400 },
65 /* screen burner section, outact MUST BE THE LAST, see the set_values */
66 { "screen_on", &burnon, FMT_UINT1, FLG_MODIFY0x0008|FLG_INIT0x0400 },
67 { "screen_off", &burnoff, FMT_UINT1, FLG_MODIFY0x0008|FLG_INIT0x0400 },
68 { "vblank", &vblank, FMT_BOOL3, FLG_MODIFY0x0008|FLG_INIT0x0400 },
69 { "kbdact", &kbdact, FMT_BOOL3, FLG_MODIFY0x0008|FLG_INIT0x0400 },
70 { "msact", &msact, FMT_BOOL3, FLG_MODIFY0x0008|FLG_INIT0x0400 },
71 { "outact", &outact, FMT_BOOL3, FLG_MODIFY0x0008|FLG_INIT0x0400 },
72 { "font", fontname, FMT_STRING109, FLG_WRONLY0x0002 },
73 { NULL((void *)0) }
74};
75
76#define fillioctl(n){ cmd = n; cmd_str = "n"; } { cmd = n; cmd_str = #n; }
77
78void
79display_get_values(int fd)
80{
81 struct wsdisplay_addscreendata gscr;
82 struct wsdisplay_param param;
83 struct wsdisplay_burner burners;
84 struct wsdisplay_fbinfo fbinfo;
85 struct field *pf;
86 const char *cmd_str;
1
'cmd_str' declared without an initial value
87 void *ptr;
88 unsigned long cmd;
89 int bon = 0, fbon = 0, son = 0;
90
91 focus = gscr.idx = -1;
92 for (pf = display_field_tab; pf->name; pf++) {
2
Loop condition is true. Entering loop body
93
94 if (!(pf->flags & FLG_GET0x0100) || pf->flags & FLG_DEAD0x0800)
3
Assuming the condition is false
4
Assuming the condition is false
5
Taking false branch
95 continue;
96
97 ptr = pf->valp;
98
99 if (ptr == &dpytype) {
6
Assuming the condition is false
7
Taking false branch
100 fillioctl(WSDISPLAYIO_GTYPE){ cmd = ((unsigned long)0x40000000 | ((sizeof(u_int) & 0x1fff
) << 16) | ((('W')) << 8) | ((64))); cmd_str = "WSDISPLAYIO_GTYPE"
; }
;
101 } else if (ptr == &focus) {
8
Assuming the condition is false
9
Taking false branch
102 fillioctl(WSDISPLAYIO_GETSCREEN){ cmd = (((unsigned long)0x80000000|(unsigned long)0x40000000
) | ((sizeof(struct wsdisplay_addscreendata) & 0x1fff) <<
16) | ((('W')) << 8) | ((85))); cmd_str = "WSDISPLAYIO_GETSCREEN"
; }
;
103 ptr = &gscr;
104 } else if (ptr == &emuls) {
10
Assuming the condition is false
11
Taking false branch
105 fillioctl(WSDISPLAYIO_GETEMULTYPE){ cmd = (((unsigned long)0x80000000|(unsigned long)0x40000000
) | ((sizeof(struct wsdisplay_emultype) & 0x1fff) <<
16) | ((('W')) << 8) | ((94))); cmd_str = "WSDISPLAYIO_GETEMULTYPE"
; }
;
106 emuls.idx=0;
107 } else if (ptr == &fontwidth || ptr == &fontheight) {
12
Assuming the condition is false
13
Assuming the condition is false
14
Taking false branch
108 fillioctl(WSDISPLAYIO_GETSCREENTYPE){ cmd = (((unsigned long)0x80000000|(unsigned long)0x40000000
) | ((sizeof(struct wsdisplay_screentype) & 0x1fff) <<
16) | ((('W')) << 8) | ((93))); cmd_str = "WSDISPLAYIO_GETSCREENTYPE"
; }
;
109 ptr = &screens;
110 screens.idx = 0;
111 } else if (ptr == &screens) {
15
Assuming the condition is false
16
Taking false branch
112 fillioctl(WSDISPLAYIO_GETSCREENTYPE){ cmd = (((unsigned long)0x80000000|(unsigned long)0x40000000
) | ((sizeof(struct wsdisplay_screentype) & 0x1fff) <<
16) | ((('W')) << 8) | ((93))); cmd_str = "WSDISPLAYIO_GETSCREENTYPE"
; }
;
113 screens.idx=0;
114 } else if (ptr == &brightness) {
17
Assuming the condition is false
18
Taking false branch
115 ptr = &param;
116 param.param = WSDISPLAYIO_PARAM_BRIGHTNESS2;
117 } else if (ptr == &contrast) {
19
Assuming the condition is false
20
Taking false branch
118 ptr = &param;
119 param.param = WSDISPLAYIO_PARAM_CONTRAST3;
120 } else if (ptr == &backlight) {
21
Assuming the condition is false
22
Taking false branch
121 ptr = &param;
122 param.param = WSDISPLAYIO_PARAM_BACKLIGHT1;
123 } else if (ptr == &burnon || ptr == &burnoff ||
23
Assuming the condition is false
24
Assuming the condition is false
29
Taking false branch
124 ptr == &vblank || ptr == &kbdact ||
25
Assuming the condition is false
26
Assuming the condition is false
125 ptr == &outact || ptr == &msact) {
27
Assuming the condition is false
28
Assuming the condition is false
126 fillioctl(WSDISPLAYIO_GBURNER){ cmd = ((unsigned long)0x40000000 | ((sizeof(struct wsdisplay_burner
) & 0x1fff) << 16) | ((('W')) << 8) | ((82)))
; cmd_str = "WSDISPLAYIO_GBURNER"; }
;
127 ptr = &burners;
128 if (!bon)
129 bzero(&burners, sizeof(burners));
130 } else if (ptr == &height || ptr == &width ||
30
Assuming the condition is false
31
Assuming the condition is false
33
Taking false branch
131 ptr == &depth) {
32
Assuming the condition is false
132 fillioctl(WSDISPLAYIO_GINFO){ cmd = ((unsigned long)0x40000000 | ((sizeof(struct wsdisplay_fbinfo
) & 0x1fff) << 16) | ((('W')) << 8) | ((65)))
; cmd_str = "WSDISPLAYIO_GINFO"; }
;
133 ptr = &fbinfo;
134 if (!fbon)
135 bzero(&fbinfo, sizeof(fbinfo));
136 } else
137 cmd = 0;
138
139 if (ptr == &param) {
34
Taking false branch
140 fillioctl(WSDISPLAYIO_GETPARAM){ cmd = (((unsigned long)0x80000000|(unsigned long)0x40000000
) | ((sizeof(struct wsdisplay_param) & 0x1fff) << 16
) | ((('W')) << 8) | ((89))); cmd_str = "WSDISPLAYIO_GETPARAM"
; }
;
141 }
142
143 if ((cmd != WSDISPLAYIO_GBURNER((unsigned long)0x40000000 | ((sizeof(struct wsdisplay_burner
) & 0x1fff) << 16) | ((('W')) << 8) | ((82)))
&& cmd != WSDISPLAYIO_GINFO((unsigned long)0x40000000 | ((sizeof(struct wsdisplay_fbinfo
) & 0x1fff) << 16) | ((('W')) << 8) | ((65)))
) ||
144 (cmd == WSDISPLAYIO_GBURNER((unsigned long)0x40000000 | ((sizeof(struct wsdisplay_burner
) & 0x1fff) << 16) | ((('W')) << 8) | ((82)))
&& !bon) ||
145 (cmd == WSDISPLAYIO_GINFO((unsigned long)0x40000000 | ((sizeof(struct wsdisplay_fbinfo
) & 0x1fff) << 16) | ((('W')) << 8) | ((65)))
&& !fbon)) {
146 errno(*__errno()) = ENOTTY25;
147 if (!cmd
34.1
'cmd' is 0
|| ioctl(fd, cmd, ptr) == -1) {
148 if (errno(*__errno()) == ENOTTY25) {
35
Assuming the condition is false
36
Taking false branch
149 pf->flags |= FLG_DEAD0x0800;
150 continue;
151 } else
152 warn("%s", cmd_str);
37
2nd function call argument is an uninitialized value
153 }
154 }
155
156 if (ptr == &burners) {
157 if (!bon) {
158 burnon = burners.on;
159 burnoff = burners.off;
160 vblank = burners.flags & WSDISPLAY_BURN_VBLANK0x0001;
161 kbdact = burners.flags & WSDISPLAY_BURN_KBD0x0002;
162 msact = burners.flags & WSDISPLAY_BURN_MOUSE0x0004;
163 outact = burners.flags & WSDISPLAY_BURN_OUTPUT0x0008;
164 }
165 bon++;
166 } else if (ptr == &fbinfo) {
167 if (!fbon) {
168 width = fbinfo.width;
169 height = fbinfo.height;
170 depth = fbinfo.depth;
171 }
172 fbon++;
173 } else if (ptr == &emuls) {
174 emuls.idx=fd;
175 } else if (ptr == &screens) {
176 screens.idx=fd;
177 if (!son) {
178 fontwidth = screens.fontwidth;
179 fontheight = screens.fontheight;
180 }
181 son++;
182 } else if (ptr == &param) {
183 struct field_pc *pc = pf->valp;
184
185 pc->min = param.min;
186 pc->cur = param.curval;
187 pc->max = param.max;
188 } else if (ptr == &gscr)
189 focus = gscr.idx;
190 }
191}
192
193int
194display_put_values(int fd)
195{
196 struct wsdisplay_param param;
197 struct wsdisplay_burner burners;
198 struct wsdisplay_font font;
199 struct field *pf;
200 const char *cmd_str;
201 void *ptr;
202 unsigned long cmd;
203 int id;
204
205 for (pf = display_field_tab; pf->name; pf++) {
206
207 if (!(pf->flags & FLG_SET0x0200) || pf->flags & FLG_DEAD0x0800)
208 continue;
209
210 ptr = pf->valp;
211
212 if (ptr == &focus) {
213 fillioctl(WSDISPLAYIO_SETSCREEN){ cmd = ((unsigned long)0x80000000 | ((sizeof(u_int) & 0x1fff
) << 16) | ((('W')) << 8) | ((86))); cmd_str = "WSDISPLAYIO_SETSCREEN"
; }
;
214 } else if (ptr == &brightness) {
215 ptr = &param;
216 id = WSDISPLAYIO_PARAM_BRIGHTNESS2;
217 } else if (ptr == &contrast) {
218 ptr = &param;
219 id = WSDISPLAYIO_PARAM_CONTRAST3;
220 } else if (ptr == &backlight) {
221 ptr = &param;
222 id = WSDISPLAYIO_PARAM_BACKLIGHT1;
223 } else if (ptr == &burnon || ptr == &burnoff ||
224 ptr == &vblank || ptr == &kbdact ||
225 ptr == &outact || ptr == &msact) {
226
227 bzero(&burners, sizeof(burners));
228 burners.on = burnon;
229 burners.off = burnoff;
230 if (vblank)
231 burners.flags |= WSDISPLAY_BURN_VBLANK0x0001;
232 else
233 burners.flags &= ~WSDISPLAY_BURN_VBLANK0x0001;
234 if (kbdact)
235 burners.flags |= WSDISPLAY_BURN_KBD0x0002;
236 else
237 burners.flags &= ~WSDISPLAY_BURN_KBD0x0002;
238 if (msact)
239 burners.flags |= WSDISPLAY_BURN_MOUSE0x0004;
240 else
241 burners.flags &= ~WSDISPLAY_BURN_MOUSE0x0004;
242 if (outact)
243 burners.flags |= WSDISPLAY_BURN_OUTPUT0x0008;
244 else
245 burners.flags &= ~WSDISPLAY_BURN_OUTPUT0x0008;
246
247 fillioctl(WSDISPLAYIO_SBURNER){ cmd = ((unsigned long)0x80000000 | ((sizeof(struct wsdisplay_burner
) & 0x1fff) << 16) | ((('W')) << 8) | ((81)))
; cmd_str = "WSDISPLAYIO_SBURNER"; }
;
248 ptr = &burners;
249 } else if (ptr == fontname) {
250 bzero(&font, sizeof(font));
251 strlcpy(font.name, ptr, sizeof font.name);
252 fillioctl(WSDISPLAYIO_USEFONT){ cmd = ((unsigned long)0x80000000 | ((sizeof(struct wsdisplay_font
) & 0x1fff) << 16) | ((('W')) << 8) | ((80)))
; cmd_str = "WSDISPLAYIO_USEFONT"; }
;
253 } else
254 cmd = 0;
255
256 if (ptr == &param) {
257 struct field_pc *pc = pf->valp;
258
259 bzero(&param, sizeof(param));
260 param.param = id;
261 param.min = pc->min;
262 param.curval = pc->cur;
263 param.max = pc->max;
264 fillioctl(WSDISPLAYIO_SETPARAM){ cmd = (((unsigned long)0x80000000|(unsigned long)0x40000000
) | ((sizeof(struct wsdisplay_param) & 0x1fff) << 16
) | ((('W')) << 8) | ((90))); cmd_str = "WSDISPLAYIO_SETPARAM"
; }
;
265 }
266
267 errno(*__errno()) = ENOTTY25;
268 if (!cmd || ioctl(fd, cmd, ptr) == -1) {
269 if (errno(*__errno()) == ENOTTY25) {
270 pf->flags |= FLG_DEAD0x0800;
271 continue;
272 } else {
273 warn("%s", cmd_str);
274 return 1;
275 }
276 }
277 }
278
279 return 0;
280}
281
282char *
283display_next_device(int index)
284{
285 static char devname[20];
286
287 if (index > 7)
288 return (NULL((void *)0));
289
290 snprintf(devname, sizeof(devname), "/dev/tty%c0", index + 'C');
291 return (devname);
292}