dbus-glib-bash-completion.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. From 484e483d1fb98b56ebd2cb7d73a7f0851f7b4ab5 Mon Sep 17 00:00:00 2001
  2. From: Koki Fukuda <ko.fu.dev@gmail.com>
  3. Date: Wed, 5 May 2021 21:59:34 +0900
  4. Subject: [PATCH] Fix bash completion and its helper
  5. This fixes the following errors:
  6. * Completion script causing an usage error.
  7. * Better error handling in helper program in case the bus
  8. is inaccessible.
  9. ---
  10. dbus/dbus-bash-completion-helper.c | 43 ++++++++++++++++++++++++++++++
  11. dbus/dbus-bash-completion.sh.in | 3 +--
  12. 2 files changed, 44 insertions(+), 2 deletions(-)
  13. diff --git a/dbus/dbus-bash-completion-helper.c b/dbus/dbus-bash-completion-helper.c
  14. index 6240ed6..2dcae22 100644
  15. --- a/dbus/dbus-bash-completion-helper.c
  16. +++ b/dbus/dbus-bash-completion-helper.c
  17. @@ -56,6 +56,11 @@ print_services (DBusConnection *connection)
  18. -1,
  19. &error);
  20. dbus_message_unref (message);
  21. +
  22. + if (reply == NULL) {
  23. + goto fail;
  24. + }
  25. +
  26. dbus_message_iter_init (reply, &iter);
  27. dbus_message_iter_recurse (&iter, &iter_array);
  28. while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
  29. @@ -77,6 +82,11 @@ print_services (DBusConnection *connection)
  30. -1,
  31. &error);
  32. dbus_message_unref (message);
  33. +
  34. + if (reply == NULL) {
  35. + goto fail;
  36. + }
  37. +
  38. dbus_message_iter_init (reply, &iter);
  39. dbus_message_iter_recurse (&iter, &iter_array);
  40. while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
  41. @@ -86,6 +96,9 @@ print_services (DBusConnection *connection)
  42. dbus_message_iter_next (&iter_array);
  43. }
  44. dbus_message_unref (reply);
  45. +
  46. + fail:
  47. + dbus_error_free(&error);
  48. }
  49. static gboolean
  50. @@ -139,6 +152,11 @@ print_objects (DBusConnection *connection, const char *service_name, const char
  51. -1,
  52. &error);
  53. dbus_message_unref (message);
  54. +
  55. + if (reply == NULL) {
  56. + goto fail;
  57. + }
  58. +
  59. dbus_message_iter_init (reply, &iter);
  60. dbus_message_iter_get_basic (&iter, &introspection_xml);
  61. @@ -167,6 +185,9 @@ print_objects (DBusConnection *connection, const char *service_name, const char
  62. node_info_unref (root);
  63. dbus_message_unref (reply);
  64. +
  65. + fail:
  66. + dbus_error_free(&error);
  67. }
  68. static gboolean
  69. @@ -192,6 +213,11 @@ is_object_path_with_interfaces (DBusConnection *connection, const char *service_
  70. -1,
  71. &error);
  72. dbus_message_unref (message);
  73. +
  74. + if (reply == NULL) {
  75. + goto fail;
  76. + }
  77. +
  78. dbus_message_iter_init (reply, &iter);
  79. dbus_message_iter_get_basic (&iter, &introspection_xml);
  80. @@ -203,6 +229,9 @@ is_object_path_with_interfaces (DBusConnection *connection, const char *service_
  81. node_info_unref (root);
  82. dbus_message_unref (reply);
  83. + fail:
  84. + dbus_error_free(&error);
  85. +
  86. return ret;
  87. }
  88. @@ -228,6 +257,11 @@ print_methods (DBusConnection *connection, const char *service_name, const char
  89. -1,
  90. &error);
  91. dbus_message_unref (message);
  92. +
  93. + if (reply == NULL) {
  94. + goto fail;
  95. + }
  96. +
  97. dbus_message_iter_init (reply, &iter);
  98. dbus_message_iter_get_basic (&iter, &introspection_xml);
  99. @@ -247,6 +281,9 @@ print_methods (DBusConnection *connection, const char *service_name, const char
  100. }
  101. node_info_unref (root);
  102. dbus_message_unref (reply);
  103. +
  104. + fail:
  105. + dbus_error_free(&error);
  106. }
  107. static void
  108. @@ -285,6 +322,11 @@ print_signature (DBusConnection *connection, const char *service_name, const cha
  109. -1,
  110. &error);
  111. dbus_message_unref (message);
  112. +
  113. + if (reply == NULL) {
  114. + goto fail;
  115. + }
  116. +
  117. dbus_message_iter_init (reply, &iter);
  118. dbus_message_iter_get_basic (&iter, &introspection_xml);
  119. @@ -324,6 +366,7 @@ print_signature (DBusConnection *connection, const char *service_name, const cha
  120. node_info_unref (root);
  121. dbus_message_unref (reply);
  122. fail:
  123. + dbus_error_free(&error);
  124. g_free (method_name);
  125. g_free (interface_name);
  126. }
  127. diff --git a/dbus/dbus-bash-completion.sh.in b/dbus/dbus-bash-completion.sh.in
  128. index a7751da..e582438 100644
  129. --- a/dbus/dbus-bash-completion.sh.in
  130. +++ b/dbus/dbus-bash-completion.sh.in
  131. @@ -5,7 +5,6 @@
  132. ################################################################################
  133. __dbus_send() {
  134. - local IFS=$'\n'
  135. local cur="${COMP_WORDS[COMP_CWORD]}"
  136. # --name=value style option
  137. @@ -13,7 +12,7 @@ __dbus_send() {
  138. cur=${cur/*=/}
  139. fi
  140. - COMPREPLY=($(compgen -W "$(@libexecdir@/dbus-bash-completion-helper dbus-send ${COMP_WORDS[@]:0})" -- $cur))
  141. + COMPREPLY=($(compgen -W "$(@libexecdir@/dbus-bash-completion-helper dbus-send "${COMP_LINE}")" -- $cur))
  142. }
  143. ################################################################################
  144. --
  145. GitLab