Skip to content

Commit eba48ef

Browse files
committed
[xmlrpc-c] Coverity 1024180, 1024205, 1024301, 1024847, 1024848, 1024377, 1024378, 1024379, 1024380, 1024381, 1024584, 1024495, 1214208 fixes.
1 parent da7300b commit eba48ef

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

libs/xmlrpc-c/lib/abyss/src/handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ sendDirectoryDocument(TList * const listP,
305305
if (k > 24) {
306306
snprintf(z1, sizeof(z1), "%.10s...%s", z, z + k - 11);
307307
k = 24;
308-
p = z1 + 24;
308+
p = z1 + k;
309309
} else {
310310
snprintf(z1, sizeof(z1), "%s", z);
311311

libs/xmlrpc-c/lib/expat/xmlparse/xmlparse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,7 @@ doStartTagNoAtts(XML_Parser const xmlParserP,
24162416
}
24172417
tag->buf = malloc(INIT_TAG_BUF_SIZE);
24182418
if (!tag->buf) {
2419+
free(tag);
24192420
*errorCodeP = XML_ERROR_NO_MEMORY;
24202421
return;
24212422
}
@@ -3646,8 +3647,10 @@ doProlog(XML_Parser const xmlParserP,
36463647
switch (tok) {
36473648
case XML_TOK_PARAM_ENTITY_REF:
36483649
*errorCodeP = XML_ERROR_PARAM_ENTITY_REF;
3650+
break;
36493651
case XML_TOK_XML_DECL:
36503652
*errorCodeP = XML_ERROR_MISPLACED_XML_PI;
3653+
break;
36513654
default:
36523655
*errorCodeP = XML_ERROR_SYNTAX;
36533656
}

libs/xmlrpc-c/lib/libutil/utf8.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ decodeMultibyte(xmlrpc_env * const envP,
170170
171171
Return the character in UTF-16 format as *wcP.
172172
-----------------------------------------------------------------------------*/
173-
wchar_t wc;
173+
wchar_t wc = 0;
174174

175175
assert(utf8_seq[0] & 0x80); /* High bit set: this is multibyte seq */
176176

libs/xmlrpc-c/src/xmlrpc_decompose.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ releaseDecompArray(struct arrayDecomp const arrayDecomp,
181181

182182

183183
static void
184-
releaseDecompStruct(struct structDecomp const structDecomp,
184+
releaseDecompStruct(struct structDecomp const *_structDecomp,
185185
bool const oldstyleMemMgmt) {
186186

187+
struct structDecomp const structDecomp = *_structDecomp;
187188
unsigned int i;
188189
for (i = 0; i < structDecomp.mbrCnt; ++i) {
189190
releaseDecomposition(structDecomp.mbrArray[i].decompTreeP,
@@ -239,7 +240,7 @@ releaseDecomposition(const struct decompTreeNode * const decompRootP,
239240
releaseDecompArray(decompRootP->store.Tarray, oldstyleMemMgmt);
240241
break;
241242
case '{':
242-
releaseDecompStruct(decompRootP->store.Tstruct, oldstyleMemMgmt);
243+
releaseDecompStruct(&decompRootP->store.Tstruct, oldstyleMemMgmt);
243244
break;
244245
}
245246
}
@@ -259,8 +260,9 @@ decomposeValueWithTree(xmlrpc_env * const envP,
259260
static void
260261
validateArraySize(xmlrpc_env * const envP,
261262
const xmlrpc_value * const arrayP,
262-
struct arrayDecomp const arrayDecomp) {
263+
struct arrayDecomp const *_arrayDecomp) {
263264

265+
struct arrayDecomp const arrayDecomp = *_arrayDecomp;
264266
unsigned int size;
265267

266268
size = xmlrpc_array_size(envP, arrayP);
@@ -284,10 +286,12 @@ validateArraySize(xmlrpc_env * const envP,
284286
static void
285287
parsearray(xmlrpc_env * const envP,
286288
const xmlrpc_value * const arrayP,
287-
struct arrayDecomp const arrayDecomp,
289+
struct arrayDecomp const *_arrayDecomp,
288290
bool const oldstyleMemMgmt) {
289291

290-
validateArraySize(envP, arrayP, arrayDecomp);
292+
struct arrayDecomp const arrayDecomp = *_arrayDecomp;
293+
294+
validateArraySize(envP, arrayP, &arrayDecomp);
291295

292296
if (!envP->fault_occurred) {
293297
unsigned int doneCnt;
@@ -324,9 +328,10 @@ parsearray(xmlrpc_env * const envP,
324328
static void
325329
parsestruct(xmlrpc_env * const envP,
326330
xmlrpc_value * const structP,
327-
struct structDecomp const structDecomp,
331+
struct structDecomp const *_structDecomp,
328332
bool const oldstyleMemMgmt) {
329333

334+
struct structDecomp const structDecomp = *_structDecomp;
330335
unsigned int doneCount;
331336

332337
doneCount = 0; /* No members done yet */
@@ -569,7 +574,7 @@ decomposeValueWithTree(xmlrpc_env * const envP,
569574
"%s, but the '(...)' specifier requires type ARRAY",
570575
xmlrpc_type_name(xmlrpc_value_type(valueP)));
571576
else
572-
parsearray(envP, valueP, decompRootP->store.Tarray,
577+
parsearray(envP, valueP, &decompRootP->store.Tarray,
573578
oldstyleMemMgmt);
574579
break;
575580

@@ -580,7 +585,7 @@ decomposeValueWithTree(xmlrpc_env * const envP,
580585
"%s, but the '{...}' specifier requires type STRUCT",
581586
xmlrpc_type_name(xmlrpc_value_type(valueP)));
582587
else
583-
parsestruct(envP, valueP, decompRootP->store.Tstruct,
588+
parsestruct(envP, valueP, &decompRootP->store.Tstruct,
584589
oldstyleMemMgmt);
585590
break;
586591

libs/xmlrpc-c/src/xmlrpc_server_abyss.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ sendResponse(xmlrpc_env * const envP,
179179

180180
ResponseStatus(abyssSessionP, 200);
181181

182+
#if 0 /* Uncomment once http_cookie is not NULL again */
182183
if (http_cookie)
183184
/* There's an auth cookie, so pass it back in the response. */
184185
addAuthCookie(envP, abyssSessionP, http_cookie);
186+
#endif
185187

186188
if ((size_t)(uint32_t)len != len)
187189
xmlrpc_faultf(envP, "XML-RPC method generated a response too "

libs/xmlrpc-c/src/xmlrpc_server_cgi.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ xmlrpc_server_cgi_process_call(xmlrpc_registry * const registryP) {
189189
size_t input_size, output_size;
190190
int code;
191191
char *message;
192+
char *err = NULL;
192193

193194
/* Error-handling preconditions. */
194195
xmlrpc_env_init(&env);
@@ -209,13 +210,13 @@ xmlrpc_server_cgi_process_call(xmlrpc_registry * const registryP) {
209210
}
210211
if (!type || !xmlrpc_strneq(type, "text/xml", strlen("text/xml"))) {
211212
char *template = "Expected content type: \"text/xml\", received: \"%s\"";
212-
size_t err_len = strlen(template) + strlen(type) + 1;
213-
char *err = malloc(err_len);
213+
size_t err_len = strlen(template) + (type ? strlen(type) : 0) + 1;
214214

215-
(void)snprintf(err, err_len, template, type);
215+
err = malloc(err_len);
216+
217+
(void)snprintf(err, err_len, template, (type ? type : ""));
216218
code = 400; message = "Bad Request";
217219
XMLRPC_FAIL(&env, XMLRPC_INTERNAL_ERROR, err);
218-
free(err);
219220
}
220221
if (!length_str) {
221222
code = 411; message = "Length Required";
@@ -254,6 +255,8 @@ xmlrpc_server_cgi_process_call(xmlrpc_registry * const registryP) {
254255
send_xml(output_data, output_size);
255256

256257
cleanup:
258+
if (err)
259+
free(err);
257260
if (input)
258261
xmlrpc_mem_block_free(input);
259262
if (output)

0 commit comments

Comments
 (0)