logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0003-Avoid-use-of-statement-expressions.patch (4249B)


  1. From 30dafd9bd223318058b5c2e5577bf4cf5b853f6d Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Wed, 1 Apr 2026 22:05:31 -0700
  4. Subject: [PATCH] Avoid use of statement expressions
  5. ---
  6. src/ipc-uapi.h | 65 +++++++++++++++++++++++++++++++-------------------
  7. 1 file changed, 41 insertions(+), 24 deletions(-)
  8. diff --git a/src/ipc-uapi.h b/src/ipc-uapi.h
  9. index 1d8a271..e9f4059 100644
  10. --- a/src/ipc-uapi.h
  11. +++ b/src/ipc-uapi.h
  12. @@ -124,16 +124,16 @@ out:
  13. return ret;
  14. }
  15. -#define NUM(max) ({ \
  16. - unsigned long long num; \
  17. - char *end; \
  18. - if (!char_is_digit(value[0])) \
  19. - break; \
  20. - num = strtoull(value, &end, 10); \
  21. - if (*end || num > max) \
  22. - break; \
  23. - num; \
  24. -})
  25. +static bool num_from_str(const char *value, unsigned long long max, unsigned long long *num)
  26. +{
  27. + char *end;
  28. + if (!char_is_digit(value[0]))
  29. + return false;
  30. + *num = strtoull(value, &end, 10);
  31. + if (*end || *num > max)
  32. + return false;
  33. + return true;
  34. +}
  35. static int userspace_get_device(struct wgdevice **out, const char *iface)
  36. {
  37. @@ -144,6 +144,7 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
  38. char *key = NULL, *value;
  39. FILE *f;
  40. int ret = -EPROTO;
  41. + unsigned long long num;
  42. *out = dev = calloc(1, sizeof(*dev));
  43. if (!dev)
  44. @@ -178,10 +179,14 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
  45. curve25519_generate_public(dev->public_key, dev->private_key);
  46. dev->flags |= WGDEVICE_HAS_PRIVATE_KEY | WGDEVICE_HAS_PUBLIC_KEY;
  47. } else if (!peer && !strcmp(key, "listen_port")) {
  48. - dev->listen_port = NUM(0xffffU);
  49. + if (!num_from_str(value, 0xffffU, &num))
  50. + break;
  51. + dev->listen_port = num;
  52. dev->flags |= WGDEVICE_HAS_LISTEN_PORT;
  53. } else if (!peer && !strcmp(key, "fwmark")) {
  54. - dev->fwmark = NUM(0xffffffffU);
  55. + if (!num_from_str(value, 0xffffffffU, &num))
  56. + break;
  57. + dev->fwmark = num;
  58. dev->flags |= WGDEVICE_HAS_FWMARK;
  59. } else if (!strcmp(key, "public_key")) {
  60. struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));
  61. @@ -242,7 +247,9 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
  62. }
  63. freeaddrinfo(resolved);
  64. } else if (peer && !strcmp(key, "persistent_keepalive_interval")) {
  65. - peer->persistent_keepalive_interval = NUM(0xffffU);
  66. + if (!num_from_str(value, 0xffffU, &num))
  67. + break;
  68. + peer->persistent_keepalive_interval = num;
  69. peer->flags |= WGPEER_HAS_PERSISTENT_KEEPALIVE_INTERVAL;
  70. } else if (peer && !strcmp(key, "allowed_ip")) {
  71. struct wgallowedip *new_allowedip;
  72. @@ -271,16 +278,27 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
  73. allowedip->cidr = strtoul(mask, &end, 10);
  74. if (*end || allowedip->family == AF_UNSPEC || (allowedip->family == AF_INET6 && allowedip->cidr > 128) || (allowedip->family == AF_INET && allowedip->cidr > 32))
  75. break;
  76. - } else if (peer && !strcmp(key, "last_handshake_time_sec"))
  77. - peer->last_handshake_time.tv_sec = NUM(0x7fffffffffffffffULL);
  78. - else if (peer && !strcmp(key, "last_handshake_time_nsec"))
  79. - peer->last_handshake_time.tv_nsec = NUM(0x7fffffffffffffffULL);
  80. - else if (peer && !strcmp(key, "rx_bytes"))
  81. - peer->rx_bytes = NUM(0xffffffffffffffffULL);
  82. - else if (peer && !strcmp(key, "tx_bytes"))
  83. - peer->tx_bytes = NUM(0xffffffffffffffffULL);
  84. - else if (!strcmp(key, "errno"))
  85. - ret = -NUM(0x7fffffffU);
  86. + } else if (peer && !strcmp(key, "last_handshake_time_sec")) {
  87. + if (!num_from_str(value, 0x7fffffffffffffffULL, &num))
  88. + break;
  89. + peer->last_handshake_time.tv_sec = num;
  90. + } else if (peer && !strcmp(key, "last_handshake_time_nsec")) {
  91. + if (!num_from_str(value, 0x7fffffffffffffffULL, &num))
  92. + break;
  93. + peer->last_handshake_time.tv_nsec = num;
  94. + } else if (peer && !strcmp(key, "rx_bytes")) {
  95. + if (!num_from_str(value, 0xffffffffffffffffULL, &num))
  96. + break;
  97. + peer->rx_bytes = num;
  98. + } else if (peer && !strcmp(key, "tx_bytes")) {
  99. + if (!num_from_str(value, 0xffffffffffffffffULL, &num))
  100. + break;
  101. + peer->tx_bytes = num;
  102. + } else if (!strcmp(key, "errno")) {
  103. + if (!num_from_str(value, 0x7fffffffU, &num))
  104. + break;
  105. + ret = -num;
  106. + }
  107. }
  108. ret = -EPROTO;
  109. err:
  110. @@ -294,4 +312,3 @@ err:
  111. return ret;
  112. }
  113. -#undef NUM
  114. --
  115. 2.49.0