Bug Summary

File:src/Host.c
Location:line 97, column 2
Description:Null pointer argument in call to memory copy function

Annotated Source Code

1/*
2
3Copyright 1986, 1998 The Open Group
4
5All rights reserved.
6
7Permission is hereby granted, free of charge, to any person obtaining a
8copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, and/or sell copies of the Software, and to permit persons
12to whom the Software is furnished to do so, provided that the above
13copyright notice(s) and this permission notice appear in all copies of
14the Software and that both the above copyright notice(s) and this
15permission notice appear in supporting documentation.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
20OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
22INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
23FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
24NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
25WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26
27Except as contained in this notice, the name of a copyright holder
28shall not be used in advertising or otherwise to promote the sale, use
29or other dealings in this Software without prior written authorization
30of the copyright holder.
31
32X Window System is a trademark of The Open Group.
33
34*/
35
36/*
37 * Copyright 2004 Oracle and/or its affiliates. All rights reserved.
38 *
39 * Permission is hereby granted, free of charge, to any person obtaining a
40 * copy of this software and associated documentation files (the "Software"),
41 * to deal in the Software without restriction, including without limitation
42 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
43 * and/or sell copies of the Software, and to permit persons to whom the
44 * Software is furnished to do so, subject to the following conditions:
45 *
46 * The above copyright notice and this permission notice (including the next
47 * paragraph) shall be included in all copies or substantial portions of the
48 * Software.
49 *
50 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
53 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
55 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
56 * DEALINGS IN THE SOFTWARE.
57 */
58
59
60/* this might be rightly regarded an os dependent file */
61
62#ifdef HAVE_CONFIG_H1
63#include <config.h>
64#endif
65#include "Xlibint.h"
66
67static inline int
68changehost (Display *dpy, XHostAddress *host, BYTE mode)
69{
70 xChangeHostsReq *req;
71 int length;
72 XServerInterpretedAddress *siAddr;
73 int addrlen;
74
75 siAddr = host->family == FamilyServerInterpreted5 ?
5
'?' condition is true
76 (XServerInterpretedAddress *)host->address : NULL((void*)0);
77 addrlen = siAddr ?
6
Assuming 'siAddr' is null
7
Assuming pointer value is null
8
'?' condition is false
78 siAddr->typelength + siAddr->valuelength + 1 : host->length;
79
80 length = (addrlen + 3) & ~0x3; /* round up */
81
82 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
83 GetReqExtra (ChangeHosts, length, req)req = (xChangeHostsReq *) _XGetRequest(dpy, 109, 8 + length);
84 if (!req) {
9
Assuming 'req' is non-null
10
Taking false branch
85 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
86 return 0;
87 }
88 req->mode = mode;
89 req->hostFamily = host->family;
90 req->hostLength = addrlen;
91 if (siAddr) {
11
Taking false branch
92 char *dest = (char *) NEXTPTR(req,xChangeHostsReq)(((xChangeHostsReq *)(req)) + 1);
93 memcpy(dest, siAddr->type, siAddr->typelength)__builtin___memcpy_chk (dest, siAddr->type, siAddr->typelength
, __builtin_object_size (dest, 0))
;
94 dest[siAddr->typelength] = '\0';
95 memcpy(dest + siAddr->typelength + 1,siAddr->value,siAddr->valuelength)__builtin___memcpy_chk (dest + siAddr->typelength + 1, siAddr
->value, siAddr->valuelength, __builtin_object_size (dest
+ siAddr->typelength + 1, 0))
;
96 } else {
97 memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, addrlen)__builtin___memcpy_chk ((char *) (((xChangeHostsReq *)(req)) +
1), host->address, addrlen, __builtin_object_size ((char *
) (((xChangeHostsReq *)(req)) + 1), 0))
;
12
Within the expansion of the macro 'memcpy':
a
Null pointer argument in call to memory copy function
98 }
99 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
100 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
101 return 1;
102}
103
104int
105XAddHost (
106 register Display *dpy,
107 XHostAddress *host)
108{
109 return changehost(dpy, host, HostInsert0);
110}
111
112int
113XRemoveHost (
114 register Display *dpy,
115 XHostAddress *host)
116{
117 return changehost(dpy, host, HostDelete1);
4
Calling 'changehost'
118}
119
120int
121XAddHosts (
122 register Display *dpy,
123 XHostAddress *hosts,
124 int n)
125{
126 register int i;
127 for (i = 0; i < n; i++) {
128 (void) XAddHost(dpy, &hosts[i]);
129 }
130 return 1;
131}
132
133int
134XRemoveHosts (
135 register Display *dpy,
136 XHostAddress *hosts,
137 int n)
138{
139 register int i;
140 for (i = 0; i < n; i++) {
1
Assuming 'i' is < 'n'
2
Loop condition is true. Entering loop body
141 (void) XRemoveHost(dpy, &hosts[i]);
3
Calling 'XRemoveHost'
142 }
143 return 1;
144}