Tue, 05 Nov 2019 21:07:41 -0500
Add some NULL checks to silence scan-build.
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for asynchronous location functions. | |
| 3 | * | |
| 4 | * Created by: Marc Horowitz | |
| 5 | * | |
| 6 | * Copyright (c) 1990,1991 by the Massachusetts Institute of Technology. | |
| 7 | * For copying and distribution information, see the file | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
8 | * "mit-copyright.h". |
| 2086 | 9 | */ |
| 10 | ||
|
8791
655f64e6d1e2
[gaim-migrate @ 9553]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
11 | #include "internal.h" |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
31955
diff
changeset
|
12 | #include "util.h" |
| 2086 | 13 | |
| 14 | Code_t ZRequestLocations(user, zald, kind, auth) | |
| 7261 | 15 | const char *user; |
| 10867 | 16 | ZAsyncLocateData_t *zald; |
| 2086 | 17 | ZNotice_Kind_t kind; /* UNSAFE, UNACKED, or ACKED */ |
| 18 | Z_AuthProc auth; | |
| 19 | { | |
| 20 | int retval; | |
| 21 | ZNotice_t notice; | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
22 | size_t userlen, versionlen; |
| 2086 | 23 | |
| 24 | if (ZGetFD() < 0) | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
7261
diff
changeset
|
25 | if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE) |
| 2086 | 26 | return (retval); |
| 27 | ||
| 28 | (void) memset((char *)¬ice, 0, sizeof(notice)); | |
| 29 | notice.z_kind = kind; | |
| 30 | notice.z_port = __Zephyr_port; | |
| 31 | notice.z_class = LOCATE_CLASS; | |
| 32 | notice.z_class_inst = user; | |
| 33 | notice.z_opcode = LOCATE_LOCATE; | |
| 34 | notice.z_sender = 0; | |
| 35 | notice.z_recipient = ""; | |
| 36 | notice.z_default_format = ""; | |
| 37 | notice.z_message_len = 0; | |
| 38 | ||
| 39 | if ((retval = ZSendNotice(¬ice, auth)) != ZERR_NONE) | |
| 40 | return(retval); | |
| 41 | ||
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
42 | userlen = strlen(user) + 1; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
43 | versionlen = strlen(notice.z_version) + 1; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
44 | if ((zald->user = (char *) malloc(userlen)) == NULL) { |
| 2086 | 45 | return(ENOMEM); |
| 46 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
47 | if ((zald->version = (char *) malloc(versionlen)) == NULL) { |
| 2086 | 48 | free(zald->user); |
| 49 | return(ENOMEM); | |
| 50 | } | |
| 51 | zald->uid = notice.z_multiuid; | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
52 | g_strlcpy(zald->user,user,userlen); |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
53 | g_strlcpy(zald->version,notice.z_version,versionlen); |
| 2086 | 54 | |
| 55 | return(ZERR_NONE); | |
| 56 | } | |
| 57 | ||
| 58 | Code_t ZParseLocations(notice,zald,nlocs,user) | |
| 10867 | 59 | ZNotice_t *notice; |
| 60 | ZAsyncLocateData_t *zald; | |
| 2086 | 61 | int *nlocs; |
| 62 | char **user; | |
| 63 | { | |
| 64 | char *ptr, *end; | |
| 65 | int i; | |
| 66 | ||
| 67 | ZFlushLocations(); /* This never fails (this function is part of the | |
| 68 | library, so it is allowed to know this). */ | |
| 69 | ||
| 70 | /* non-matching protocol version numbers means the | |
| 71 | server is probably an older version--must punt */ | |
| 72 | ||
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
73 | if (zald && !purple_strequal(notice->z_version, zald->version)) |
| 2086 | 74 | return(ZERR_VERS); |
| 75 | ||
| 76 | if (notice->z_kind == SERVNAK) | |
| 77 | return (ZERR_SERVNAK); | |
| 78 | ||
| 79 | /* flag ACKs as special */ | |
| 80 | if (notice->z_kind == SERVACK && | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
31955
diff
changeset
|
81 | purple_strequal(notice->z_opcode, LOCATE_LOCATE)) { |
| 2086 | 82 | *nlocs = -1; |
| 83 | return(ZERR_NONE); | |
| 84 | } | |
| 85 | ||
| 86 | if (notice->z_kind != ACKED) | |
| 87 | return (ZERR_INTERNAL); | |
| 88 | ||
| 89 | end = notice->z_message+notice->z_message_len; | |
| 90 | ||
| 91 | __locate_num = 0; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
92 | |
| 2086 | 93 | for (ptr=notice->z_message;ptr<end;ptr++) |
| 94 | if (!*ptr) | |
| 95 | __locate_num++; | |
| 96 | ||
| 97 | __locate_num /= 3; | |
| 98 | ||
| 99 | if (__locate_num) | |
| 100 | { | |
| 101 | __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num* | |
| 102 | sizeof(ZLocations_t)); | |
| 103 | if (!__locate_list) | |
| 104 | return (ENOMEM); | |
| 105 | } else { | |
|
37390
209a1350d87f
Assign pointers to NULL rather than 0.
Michael McConville <mmcconville@mykolab.com>
parents:
37389
diff
changeset
|
106 | __locate_list = NULL; |
| 2086 | 107 | } |
| 108 | ||
| 109 | for (ptr=notice->z_message, i=0; i<__locate_num; i++) { | |
| 110 | unsigned int len; | |
| 111 | ||
| 112 | len = strlen (ptr) + 1; | |
| 113 | __locate_list[i].host = (char *) malloc(len); | |
| 114 | if (!__locate_list[i].host) | |
| 115 | return (ENOMEM); | |
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
116 | g_strlcpy(__locate_list[i].host, ptr,len); |
| 2086 | 117 | ptr += len; |
| 118 | ||
| 119 | len = strlen (ptr) + 1; | |
| 120 | __locate_list[i].time = (char *) malloc(len); | |
| 121 | if (!__locate_list[i].time) | |
| 122 | return (ENOMEM); | |
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
123 | g_strlcpy(__locate_list[i].time, ptr,len); |
| 2086 | 124 | ptr += len; |
| 125 | ||
| 126 | len = strlen (ptr) + 1; | |
| 127 | __locate_list[i].tty = (char *) malloc(len); | |
| 128 | if (!__locate_list[i].tty) | |
| 129 | return (ENOMEM); | |
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
130 | g_strlcpy(__locate_list[i].tty, ptr,len); |
| 2086 | 131 | ptr += len; |
| 132 | } | |
| 133 | ||
| 134 | __locate_next = 0; | |
| 135 | *nlocs = __locate_num; | |
| 136 | if (user) { | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
31955
diff
changeset
|
137 | size_t len; |
| 2086 | 138 | if (zald) { |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
139 | len = strlen(zald->user) + 1; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
140 | if ((*user = (char *) malloc(len)) == NULL) |
| 2086 | 141 | return(ENOMEM); |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
142 | g_strlcpy(*user,zald->user,len); |
| 2086 | 143 | } else { |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
144 | len = strlen(notice->z_class_inst) + 1; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
145 | if ((*user = (char *) malloc(len)) == NULL) |
| 2086 | 146 | return(ENOMEM); |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
147 | g_strlcpy(*user,notice->z_class_inst,len); |
| 2086 | 148 | } |
| 149 | } | |
| 150 | return (ZERR_NONE); | |
| 151 | } | |
| 152 | ||
| 153 | int ZCompareALDPred(notice, zald) | |
| 154 | ZNotice_t *notice; | |
| 155 | void *zald; | |
| 156 | { | |
| 157 | return(ZCompareUID(&(notice->z_multiuid), | |
| 158 | &(((ZAsyncLocateData_t *) zald)->uid))); | |
| 159 | } | |
| 160 | ||
| 161 | void ZFreeALD(zald) | |
| 10867 | 162 | ZAsyncLocateData_t *zald; |
| 2086 | 163 | { |
| 164 | if (!zald) return; | |
| 165 | ||
|
37389
7240fd8e3462
free() and g_free() are specified to be NULL-safe. Remove NULL checks.
Michael McConville <mmcconville@mykolab.com>
parents:
31955
diff
changeset
|
166 | free(zald->user); |
|
7240fd8e3462
free() and g_free() are specified to be NULL-safe. Remove NULL checks.
Michael McConville <mmcconville@mykolab.com>
parents:
31955
diff
changeset
|
167 | free(zald->version); |
| 2086 | 168 | (void) memset(zald, 0, sizeof(*zald)); |
| 169 | } |