diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-03-26 11:45:51 +0100 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-03-26 11:45:51 +0100 |
commit | 83beeae39bf48f3957c80bf0fd03c221bce15bc1 (patch) | |
tree | 5bb62a686532a9299011761c6d9ba9348d52399a /src/reclaim/plugin_rest_reclaim.c | |
parent | b23c010728c1c808796a7948aa7ff9f9a08966ac (diff) | |
download | gnunet-83beeae39bf48f3957c80bf0fd03c221bce15bc1.tar.gz gnunet-83beeae39bf48f3957c80bf0fd03c221bce15bc1.zip |
-fix some coverity issues wrt reclaim
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 131 |
1 files changed, 74 insertions, 57 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 84456b386..39d24ea61 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -353,14 +353,18 @@ finished_cont (void *cls, int32_t success, const char *emsg) | |||
353 | struct MHD_Response *resp; | 353 | struct MHD_Response *resp; |
354 | 354 | ||
355 | handle->idp_op = NULL; | 355 | handle->idp_op = NULL; |
356 | resp = GNUNET_REST_create_response (emsg); | ||
357 | MHD_add_response_header (resp, "Content-Type", "application/json"); | ||
358 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | ||
359 | if (GNUNET_OK != success) | 356 | if (GNUNET_OK != success) |
360 | { | 357 | { |
361 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 358 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
362 | return; | 359 | return; |
363 | } | 360 | } |
361 | resp = GNUNET_REST_create_response (emsg); | ||
362 | GNUNET_assert (MHD_NO != MHD_add_response_header (resp, | ||
363 | "Content-Type", | ||
364 | "application/json")); | ||
365 | GNUNET_assert (MHD_NO != MHD_add_response_header (resp, | ||
366 | "Access-Control-Allow-Methods", | ||
367 | allow_methods)); | ||
364 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 368 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
365 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 369 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
366 | } | 370 | } |
@@ -372,13 +376,15 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg) | |||
372 | struct RequestHandle *handle = cls; | 376 | struct RequestHandle *handle = cls; |
373 | struct MHD_Response *resp; | 377 | struct MHD_Response *resp; |
374 | 378 | ||
375 | resp = GNUNET_REST_create_response (emsg); | ||
376 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | ||
377 | if (GNUNET_OK != success) | 379 | if (GNUNET_OK != success) |
378 | { | 380 | { |
379 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 381 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
380 | return; | 382 | return; |
381 | } | 383 | } |
384 | resp = GNUNET_REST_create_response (emsg); | ||
385 | GNUNET_assert (MHD_NO != MHD_add_response_header (resp, | ||
386 | "Access-Control-Allow-Methods", | ||
387 | allow_methods)); | ||
382 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 388 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
383 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 389 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
384 | } | 390 | } |
@@ -399,7 +405,10 @@ return_response (void *cls) | |||
399 | result_str = json_dumps (handle->resp_object, 0); | 405 | result_str = json_dumps (handle->resp_object, 0); |
400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
401 | resp = GNUNET_REST_create_response (result_str); | 407 | resp = GNUNET_REST_create_response (result_str); |
402 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | 408 | GNUNET_assert (MHD_NO != |
409 | MHD_add_response_header (resp, | ||
410 | "Access-Control-Allow-Methods", | ||
411 | allow_methods)); | ||
403 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 412 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
404 | GNUNET_free (result_str); | 413 | GNUNET_free (result_str); |
405 | cleanup_handle (handle); | 414 | cleanup_handle (handle); |
@@ -461,8 +470,8 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
461 | 470 | ||
462 | static void | 471 | static void |
463 | add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | 472 | add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, |
464 | const char *url, | 473 | const char *url, |
465 | void *cls) | 474 | void *cls) |
466 | { | 475 | { |
467 | struct RequestHandle *handle = cls; | 476 | struct RequestHandle *handle = cls; |
468 | const struct GNUNET_IDENTITY_PrivateKey *identity_priv; | 477 | const struct GNUNET_IDENTITY_PrivateKey *identity_priv; |
@@ -513,7 +522,15 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
513 | handle->rest_handle->data, | 522 | handle->rest_handle->data, |
514 | handle->rest_handle->data_size); | 523 | handle->rest_handle->data_size); |
515 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | 524 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); |
516 | GNUNET_JSON_parse (data_json, attrspec, NULL, NULL); | 525 | if (GNUNET_OK != GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)) |
526 | { | ||
527 | json_decref (data_json); | ||
528 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
529 | "Unable to parse JSON from %s\n", | ||
530 | term_data); | ||
531 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
532 | return; | ||
533 | } | ||
517 | json_decref (data_json); | 534 | json_decref (data_json); |
518 | if (NULL == attribute) | 535 | if (NULL == attribute) |
519 | { | 536 | { |
@@ -530,11 +547,11 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
530 | GNUNET_RECLAIM_id_generate (&attribute->id); | 547 | GNUNET_RECLAIM_id_generate (&attribute->id); |
531 | exp = GNUNET_TIME_UNIT_HOURS; | 548 | exp = GNUNET_TIME_UNIT_HOURS; |
532 | handle->idp_op = GNUNET_RECLAIM_credential_store (idp, | 549 | handle->idp_op = GNUNET_RECLAIM_credential_store (idp, |
533 | identity_priv, | 550 | identity_priv, |
534 | attribute, | 551 | attribute, |
535 | &exp, | 552 | &exp, |
536 | &finished_cont, | 553 | &finished_cont, |
537 | handle); | 554 | handle); |
538 | GNUNET_JSON_parse_free (attrspec); | 555 | GNUNET_JSON_parse_free (attrspec); |
539 | } | 556 | } |
540 | 557 | ||
@@ -545,8 +562,8 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
545 | */ | 562 | */ |
546 | static void | 563 | static void |
547 | cred_collect (void *cls, | 564 | cred_collect (void *cls, |
548 | const struct GNUNET_IDENTITY_PublicKey *identity, | 565 | const struct GNUNET_IDENTITY_PublicKey *identity, |
549 | const struct GNUNET_RECLAIM_Credential *cred) | 566 | const struct GNUNET_RECLAIM_Credential *cred) |
550 | { | 567 | { |
551 | struct RequestHandle *handle = cls; | 568 | struct RequestHandle *handle = cls; |
552 | struct GNUNET_RECLAIM_AttributeList *attrs; | 569 | struct GNUNET_RECLAIM_AttributeList *attrs; |
@@ -565,8 +582,8 @@ cred_collect (void *cls, | |||
565 | attrs = GNUNET_RECLAIM_credential_get_attributes (cred); | 582 | attrs = GNUNET_RECLAIM_credential_get_attributes (cred); |
566 | issuer = GNUNET_RECLAIM_credential_get_issuer (cred); | 583 | issuer = GNUNET_RECLAIM_credential_get_issuer (cred); |
567 | tmp_value = GNUNET_RECLAIM_credential_value_to_string (cred->type, | 584 | tmp_value = GNUNET_RECLAIM_credential_value_to_string (cred->type, |
568 | cred->data, | 585 | cred->data, |
569 | cred->data_size); | 586 | cred->data_size); |
570 | cred_obj = json_object (); | 587 | cred_obj = json_object (); |
571 | json_object_set_new (cred_obj, "value", json_string (tmp_value)); | 588 | json_object_set_new (cred_obj, "value", json_string (tmp_value)); |
572 | json_object_set_new (cred_obj, "name", json_string (cred->name)); | 589 | json_object_set_new (cred_obj, "name", json_string (cred->name)); |
@@ -578,7 +595,7 @@ cred_collect (void *cls, | |||
578 | GNUNET_free (issuer); | 595 | GNUNET_free (issuer); |
579 | } | 596 | } |
580 | if (GNUNET_OK == GNUNET_RECLAIM_credential_get_expiration (cred, | 597 | if (GNUNET_OK == GNUNET_RECLAIM_credential_get_expiration (cred, |
581 | &exp)) | 598 | &exp)) |
582 | { | 599 | { |
583 | json_object_set_new (cred_obj, "expiration", json_integer ( | 600 | json_object_set_new (cred_obj, "expiration", json_integer ( |
584 | exp.abs_value_us)); | 601 | exp.abs_value_us)); |
@@ -613,7 +630,8 @@ cred_collect (void *cls, | |||
613 | json_object_set_new (cred_obj, "attributes", attr_arr); | 630 | json_object_set_new (cred_obj, "attributes", attr_arr); |
614 | } | 631 | } |
615 | json_array_append_new (handle->resp_object, cred_obj); | 632 | json_array_append_new (handle->resp_object, cred_obj); |
616 | GNUNET_RECLAIM_attribute_list_destroy (attrs); | 633 | if (NULL != attrs) |
634 | GNUNET_RECLAIM_attribute_list_destroy (attrs); | ||
617 | GNUNET_RECLAIM_get_credentials_next (handle->cred_it); | 635 | GNUNET_RECLAIM_get_credentials_next (handle->cred_it); |
618 | } | 636 | } |
619 | 637 | ||
@@ -627,8 +645,8 @@ cred_collect (void *cls, | |||
627 | */ | 645 | */ |
628 | static void | 646 | static void |
629 | list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | 647 | list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, |
630 | const char *url, | 648 | const char *url, |
631 | void *cls) | 649 | void *cls) |
632 | { | 650 | { |
633 | struct RequestHandle *handle = cls; | 651 | struct RequestHandle *handle = cls; |
634 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; | 652 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; |
@@ -664,14 +682,14 @@ list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
664 | } | 682 | } |
665 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 683 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
666 | handle->cred_it = GNUNET_RECLAIM_get_credentials_start (idp, | 684 | handle->cred_it = GNUNET_RECLAIM_get_credentials_start (idp, |
667 | priv_key, | 685 | priv_key, |
668 | &collect_error_cb, | 686 | &collect_error_cb, |
669 | handle, | 687 | handle, |
670 | &cred_collect, | 688 | &cred_collect, |
671 | handle, | 689 | handle, |
672 | & | 690 | & |
673 | collect_finished_cb, | 691 | collect_finished_cb, |
674 | handle); | 692 | handle); |
675 | } | 693 | } |
676 | 694 | ||
677 | 695 | ||
@@ -684,8 +702,8 @@ list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
684 | */ | 702 | */ |
685 | static void | 703 | static void |
686 | delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | 704 | delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, |
687 | const char *url, | 705 | const char *url, |
688 | void *cls) | 706 | void *cls) |
689 | { | 707 | { |
690 | struct RequestHandle *handle = cls; | 708 | struct RequestHandle *handle = cls; |
691 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; | 709 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; |
@@ -734,10 +752,10 @@ delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
734 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); | 752 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); |
735 | attr.name = ""; | 753 | attr.name = ""; |
736 | handle->idp_op = GNUNET_RECLAIM_credential_delete (idp, | 754 | handle->idp_op = GNUNET_RECLAIM_credential_delete (idp, |
737 | priv_key, | 755 | priv_key, |
738 | &attr, | 756 | &attr, |
739 | &delete_finished_cb, | 757 | &delete_finished_cb, |
740 | handle); | 758 | handle); |
741 | GNUNET_free (identity_id_str); | 759 | GNUNET_free (identity_id_str); |
742 | } | 760 | } |
743 | 761 | ||
@@ -900,8 +918,8 @@ parse_jwt (const struct GNUNET_RECLAIM_Credential *cred, | |||
900 | json_error_t *json_err = NULL; | 918 | json_error_t *json_err = NULL; |
901 | 919 | ||
902 | jwt_string = GNUNET_RECLAIM_credential_value_to_string (cred->type, | 920 | jwt_string = GNUNET_RECLAIM_credential_value_to_string (cred->type, |
903 | cred->data, | 921 | cred->data, |
904 | cred->data_size); | 922 | cred->data_size); |
905 | char *jwt_body = strtok (jwt_string, delim); | 923 | char *jwt_body = strtok (jwt_string, delim); |
906 | jwt_body = strtok (NULL, delim); | 924 | jwt_body = strtok (NULL, delim); |
907 | GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), | 925 | GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), |
@@ -1424,25 +1442,24 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1424 | static const struct GNUNET_REST_RequestHandler handlers[] = | 1442 | static const struct GNUNET_REST_RequestHandler handlers[] = |
1425 | { { MHD_HTTP_METHOD_GET, | 1443 | { { MHD_HTTP_METHOD_GET, |
1426 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont }, | 1444 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont }, |
1427 | { MHD_HTTP_METHOD_POST, | 1445 | { MHD_HTTP_METHOD_POST, |
1428 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont }, | 1446 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont }, |
1429 | { MHD_HTTP_METHOD_DELETE, | 1447 | { MHD_HTTP_METHOD_DELETE, |
1430 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont }, | 1448 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont }, |
1431 | { MHD_HTTP_METHOD_GET, | 1449 | { MHD_HTTP_METHOD_GET, |
1432 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &list_credential_cont }, | 1450 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &list_credential_cont }, |
1433 | { MHD_HTTP_METHOD_POST, | 1451 | { MHD_HTTP_METHOD_POST, |
1434 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &add_credential_cont }, | 1452 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &add_credential_cont }, |
1435 | { MHD_HTTP_METHOD_DELETE, | 1453 | { MHD_HTTP_METHOD_DELETE, |
1436 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &delete_credential_cont }, | 1454 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &delete_credential_cont }, |
1437 | { MHD_HTTP_METHOD_GET, | 1455 | { MHD_HTTP_METHOD_GET, |
1438 | GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont }, | 1456 | GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont }, |
1439 | { MHD_HTTP_METHOD_POST, | 1457 | { MHD_HTTP_METHOD_POST, |
1440 | GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont }, | 1458 | GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont }, |
1441 | { MHD_HTTP_METHOD_POST, | 1459 | { MHD_HTTP_METHOD_POST, |
1442 | GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont }, | 1460 | GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont }, |
1443 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont }, | 1461 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont }, |
1444 | GNUNET_REST_HANDLER_END | 1462 | GNUNET_REST_HANDLER_END}; |
1445 | }; | ||
1446 | 1463 | ||
1447 | handle->response_code = 0; | 1464 | handle->response_code = 0; |
1448 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1465 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |