diff --git a/src/config.c b/src/config.c index d6b3248..f087739 100644 --- a/src/config.c +++ b/src/config.c @@ -410,7 +410,7 @@ err: return false; } -static inline bool parse_string(char **device_value, const char *name, const char *value) { +static inline bool parse_awg_string(char **device_value, const char *name, const char *value) { size_t len = strlen(value); if (!len) { fprintf(stderr, "Unable to parse empty string for: %s\n", name); @@ -575,35 +575,35 @@ static bool process_line(struct config_ctx *ctx, const char *line) if (ret) ctx->device->flags |= WGDEVICE_HAS_H4; } else if (key_match("I1")) { - ret = parse_string(&ctx->device->i1, "I1", value); + ret = parse_awg_string(&ctx->device->i1, "I1", value); if (ret) ctx->device->flags |= WGDEVICE_HAS_I1; } else if (key_match("I2")) { - ret = parse_string(&ctx->device->i2, "I2", value); + ret = parse_awg_string(&ctx->device->i2, "I2", value); if (ret) ctx->device->flags |= WGDEVICE_HAS_I2; } else if (key_match("I3")) { - ret = parse_string(&ctx->device->i3, "I3", value); + ret = parse_awg_string(&ctx->device->i3, "I3", value); if (ret) ctx->device->flags |= WGDEVICE_HAS_I3; } else if (key_match("I4")) { - ret = parse_string(&ctx->device->i4, "I4", value); + ret = parse_awg_string(&ctx->device->i4, "I4", value); if (ret) ctx->device->flags |= WGDEVICE_HAS_I4; } else if (key_match("I5")) { - ret = parse_string(&ctx->device->i5, "I5", value); + ret = parse_awg_string(&ctx->device->i5, "I5", value); if (ret) ctx->device->flags |= WGDEVICE_HAS_I5; } else if (key_match("J1")) { - ret = parse_string(&ctx->device->j1, "J1", value); + ret = parse_awg_string(&ctx->device->j1, "J1", value); if (ret) ctx->device->flags |= WGDEVICE_HAS_J1; } else if (key_match("J2")) { - ret = parse_string(&ctx->device->j2, "J2", value); + ret = parse_awg_string(&ctx->device->j2, "J2", value); if (ret) ctx->device->flags |= WGDEVICE_HAS_J2; } else if (key_match("J3")) { - ret = parse_string(&ctx->device->j3, "J3", value); + ret = parse_awg_string(&ctx->device->j3, "J3", value); if (ret) ctx->device->flags |= WGDEVICE_HAS_J3; } else if (key_match("Itime")) { @@ -850,56 +850,56 @@ struct wgdevice *config_read_cmd(const char *argv[], int argc) argv += 2; argc -= 2; } else if (!strcmp(argv[0], "i1") && argc >= 2 && !peer) { - if (!parse_string(&device->i1, "i1", argv[1])) + if (!parse_awg_string(&device->i1, "i1", argv[1])) goto error; device->flags |= WGDEVICE_HAS_I1; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "i2") && argc >= 2 && !peer) { - if (!parse_string(&device->i2, "i2", argv[1])) + if (!parse_awg_string(&device->i2, "i2", argv[1])) goto error; device->flags |= WGDEVICE_HAS_I2; argv += 2; argc -=2; } else if (!strcmp(argv[0], "i3") && argc >= 2 && !peer) { - if (!parse_string(&device->i3, "i3", argv[1])) + if (!parse_awg_string(&device->i3, "i3", argv[1])) goto error; device->flags |= WGDEVICE_HAS_I3; argv += 2; argc -=2; } else if (!strcmp(argv[0], "i4") && argc >= 2 && !peer) { - if (!parse_string(&device->i4, "i4", argv[1])) + if (!parse_awg_string(&device->i4, "i4", argv[1])) goto error; device->flags |= WGDEVICE_HAS_I4; argv += 2; argc -=2; } else if (!strcmp(argv[0], "i5") && argc >= 2 && !peer) { - if (!parse_string(&device->i5, "i5", argv[1])) + if (!parse_awg_string(&device->i5, "i5", argv[1])) goto error; device->flags |= WGDEVICE_HAS_I5; argv += 2; argc -=2; } else if (!strcmp(argv[0], "j1") && argc >= 2 && !peer) { - if (!parse_string(&device->j1, "j1", argv[1])) + if (!parse_awg_string(&device->j1, "j1", argv[1])) goto error; device->flags |= WGDEVICE_HAS_J1; argv += 2; argc -=2; } else if (!strcmp(argv[0], "j2") && argc >= 2 && !peer) { - if (!parse_string(&device->j2, "j2", argv[1])) + if (!parse_awg_string(&device->j2, "j2", argv[1])) goto error; device->flags |= WGDEVICE_HAS_J2; argv += 2; argc -=2; } else if (!strcmp(argv[0], "j3") && argc >= 2 && !peer) { - if (!parse_string(&device->j3, "j3", argv[1])) + if (!parse_awg_string(&device->j3, "j3", argv[1])) goto error; device->flags |= WGDEVICE_HAS_J3; diff --git a/src/ipc-windows.h b/src/ipc-windows.h index 7695446..b269f1b 100644 --- a/src/ipc-windows.h +++ b/src/ipc-windows.h @@ -640,57 +640,57 @@ static int kernel_set_device(struct wgdevice* dev) } if (dev->flags & WG_DEVICE_HAS_I1) { - const size_t i1_size = strlen(dev->i1); - wg_iface->I1 = (UCHAR*)malloc(i1_size + 1); + const size_t i1_size = strlen(dev->i1) + 1; + wg_iface->I1 = (UCHAR*)malloc(i1_size); memcpy(wg_iface->I1, dev->i1, i1_size); dev->flags |= WG_IOCTL_INTERFACE_I1; } if (dev->flags & WG_DEVICE_HAS_I2) { - const size_t i2_size = strlen(dev->i2); - wg_iface->I2 = (UCHAR*)malloc(i2_size + 1); + const size_t i2_size = strlen(dev->i2) + 1; + wg_iface->I2 = (UCHAR*)malloc(i2_size); memcpy(wg_iface->I2, dev->i2, i2_size); dev->flags |= WG_IOCTL_INTERFACE_I2; } if (dev->flags & WG_DEVICE_HAS_I3) { - const size_t i3_size = strlen(dev->i3); - wg_iface->I3 = (UCHAR*)malloc(i3_size + 1); + const size_t i3_size = strlen(dev->i3) + 1; + wg_iface->I3 = (UCHAR*)malloc(i3_size); memcpy(wg_iface->I3, dev->i3, i3_size); dev->flags |= WG_IOCTL_INTERFACE_I3; } if (dev->flags & WG_DEVICE_HAS_I4) { - const size_t i4_size = strlen(dev->i4); - wg_iface->I4 = (UCHAR*)malloc(i4_size + 1); + const size_t i4_size = strlen(dev->i4) + 1; + wg_iface->I4 = (UCHAR*)malloc(i4_size); memcpy(wg_iface->I4, dev->i4, i4_size); dev->flags |= WG_IOCTL_INTERFACE_I4; } if (dev->flags & WG_DEVICE_HAS_I5) { - const size_t i5_size = strlen(dev->i5); - wg_iface->I5 = (UCHAR*)malloc(i5_size + 1); + const size_t i5_size = strlen(dev->i5) + 1; + wg_iface->I5 = (UCHAR*)malloc(i5_size); memcpy(wg_iface->I5, dev->i5, i5_size); dev->flags |= WG_IOCTL_INTERFACE_I5; } if (dev->flags & WG_DEVICE_HAS_J1) { - const size_t j1_size = strlen(dev->j1); - wg_iface->J1 = (UCHAR*)malloc(j1_size + 1); + const size_t j1_size = strlen(dev->j1) + 1; + wg_iface->J1 = (UCHAR*)malloc(j1_size); memcpy(wg_iface->J1, dev->j1, j1_size); dev->flags |= WG_IOCTL_INTERFACE_J1; } if (dev->flags & WG_DEVICE_HAS_J2) { - const size_t j2_size = strlen(dev->j2); - wg_iface->J2 = (UCHAR*)malloc(j2_size + 1); + const size_t j2_size = strlen(dev->j2) + 1; + wg_iface->J2 = (UCHAR*)malloc(j2_size); memcpy(wg_iface->J2, dev->j2, j2_size); dev->flags |= WG_IOCTL_INTERFACE_J2; } if (dev->flags & WG_DEVICE_HAS_J3) { - const size_t j3_size = strlen(dev->j3); - wg_iface->J3 = (UCHAR*)malloc(j3_size + 1); + const size_t j3_size = strlen(dev->j3) + 1; + wg_iface->J3 = (UCHAR*)malloc(j3_size); memcpy(wg_iface->J3, dev->j3, j3_size); dev->flags |= WG_IOCTL_INTERFACE_J3; } diff --git a/src/show.c b/src/show.c index e3c883e..66e654d 100644 --- a/src/show.c +++ b/src/show.c @@ -255,7 +255,7 @@ static void pretty_print(struct wgdevice *device) if (device->j3) terminal_printf(" " TERMINAL_BOLD "j3" TERMINAL_RESET ": %s\n", device->j3); if (device->itime) - terminal_printf(" " TERMINAL_BOLD "itime" TERMINAL_RESET ": %d\n", device->itime); + terminal_printf(" " TERMINAL_BOLD "itime" TERMINAL_RESET ": %u\n", device->itime); if (device->first_peer) { sort_peers(device); @@ -307,14 +307,14 @@ static void dump_print(struct wgdevice *device, bool with_interface) printf("%u\t", device->underload_packet_magic_header); printf("%u\t", device->transport_packet_magic_header); printf("%s\t", device->i1); - printf("%s\t", device->i2); - printf("%s\t", device->i3); - printf("%s\t", device->i4); - printf("%s\t", device->i5); - printf("%s\t", device->j1); - printf("%s\t", device->j2); - printf("%s\t", device->j3); - printf("%d\t", device->itime); + printf("%s\t", device->i2); + printf("%s\t", device->i3); + printf("%s\t", device->i4); + printf("%s\t", device->i5); + printf("%s\t", device->j1); + printf("%s\t", device->j2); + printf("%s\t", device->j3); + printf("%u\t", device->itime); if (device->fwmark) printf("0x%x\n", device->fwmark); @@ -438,7 +438,7 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int } else if(!strcmp(param, "itime")) { if (with_interface) printf("%s\t", device->name); - printf("%d\n", device->itime); + printf("%u\n", device->itime); } else if (!strcmp(param, "endpoints")) { for_each_wgpeer(device, peer) { if (with_interface) diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c index 3bff1ba..d85c48b 100644 --- a/src/wg-quick/android.c +++ b/src/wg-quick/android.c @@ -1278,23 +1278,23 @@ static void parse_options(char **iface, char **config, unsigned int *mtu, char * is_asecurity_on = true; } else if (!strncasecmp(clean, "H4=", 3) && j > 4) { is_asecurity_on = true; - } else if (!strncasecmp(clean, "I1", 3) && j > 4) { + } else if (!strncasecmp(clean, "I1=", 3) && j > 4) { is_special_handshake_on = true; - } else if (!strncasecmp(clean, "I2", 3) && j > 4) { + } else if (!strncasecmp(clean, "I2=", 3) && j > 4) { is_special_handshake_on = true; - } else if (!strncasecmp(clean, "I3", 3) && j > 4) { + } else if (!strncasecmp(clean, "I3=", 3) && j > 4) { is_special_handshake_on = true; - } else if (!strncasecmp(clean, "I4", 3) && j > 4) { + } else if (!strncasecmp(clean, "I4=", 3) && j > 4) { is_special_handshake_on = true; - } else if (!strncasecmp(clean, "I5", 3) && j > 4) { + } else if (!strncasecmp(clean, "I5=", 3) && j > 4) { is_special_handshake_on = true; - } else if (!strncasecmp(clean, "J1", 3) && j > 4) { + } else if (!strncasecmp(clean, "J1=", 3) && j > 4) { is_special_handshake_on = true; - } else if (!strncasecmp(clean, "J2", 3) && j > 4) { + } else if (!strncasecmp(clean, "J2=", 3) && j > 4) { is_special_handshake_on = true; - } else if (!strncasecmp(clean, "J3", 3) && j > 4) { + } else if (!strncasecmp(clean, "J3=", 3) && j > 4) { is_special_handshake_on = true; - } else if (!strncasecmp(clean, "Itime", 3) && j > 4) { + } else if (!strncasecmp(clean, "Itime=", 6) && j > 4) { is_special_handshake_on = true; } }