0003-PARTIAL-REVERT-commit-tree-wide-replace-strverscmp-and-str_verscmp-with-strverscmp_improved.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 9021729667e019defea0d4c1bdf563d629d7d837 Mon Sep 17 00:00:00 2001
  2. From: Ernesto Castellotti <mail@ernestocastellotti.it>
  3. Date: Sat, 10 Apr 2021 18:59:14 +0200
  4. Subject: [PATCH] PARTIAL REVERT commit tree-wide: replace strverscmp() and
  5. str_verscmp() with strverscmp_improved
  6. This is a workaround for the issue https://github.com/systemd/systemd/issues/19191
  7. ---
  8. src/boot/efi/boot.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-
  9. 1 file changed, 48 insertions(+), 1 deletion(-)
  10. diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
  11. index 35248db009bf..75c7e2c61d19 100644
  12. --- a/src/boot/efi/boot.c
  13. +++ b/src/boot/efi/boot.c
  14. @@ -914,6 +914,53 @@ static VOID config_entry_free(ConfigEntry *entry) {
  15. FreePool(entry);
  16. }
  17. +static BOOLEAN is_digit(CHAR16 c) {
  18. + return (c >= '0') && (c <= '9');
  19. +}
  20. +static UINTN c_order(CHAR16 c) {
  21. + if (c == '\0')
  22. + return 0;
  23. + if (is_digit(c))
  24. + return 0;
  25. + else if ((c >= 'a') && (c <= 'z'))
  26. + return c;
  27. + else
  28. + return c + 0x10000;
  29. +}
  30. +static INTN str_verscmp(CHAR16 *s1, CHAR16 *s2) {
  31. + CHAR16 *os1 = s1;
  32. + CHAR16 *os2 = s2;
  33. + while (*s1 || *s2) {
  34. + INTN first;
  35. + while ((*s1 && !is_digit(*s1)) || (*s2 && !is_digit(*s2))) {
  36. + INTN order;
  37. + order = c_order(*s1) - c_order(*s2);
  38. + if (order != 0)
  39. + return order;
  40. + s1++;
  41. + s2++;
  42. + }
  43. + while (*s1 == '0')
  44. + s1++;
  45. + while (*s2 == '0')
  46. + s2++;
  47. + first = 0;
  48. + while (is_digit(*s1) && is_digit(*s2)) {
  49. + if (first == 0)
  50. + first = *s1 - *s2;
  51. + s1++;
  52. + s2++;
  53. + }
  54. + if (is_digit(*s1))
  55. + return 1;
  56. + if (is_digit(*s2))
  57. + return -1;
  58. + if (first != 0)
  59. + return first;
  60. + }
  61. + return StrCmp(os1, os2);
  62. +}
  63. +
  64. static CHAR8 *line_get_key_value(
  65. CHAR8 *content,
  66. CHAR8 *sep,
  67. @@ -1478,7 +1525,7 @@ static INTN config_entry_compare(ConfigEntry *a, ConfigEntry *b) {
  68. if (a->tries_left == 0 && b->tries_left != 0)
  69. return -1;
  70. - r = strverscmp_improved(a->id, b->id);
  71. + r = str_verscmp(a->id, b->id);
  72. if (r != 0)
  73. return r;