Fw: Dillo gopher plugin on OpenBSD issue
Forwarding to dillo-dev, since the list only accepts mails from subscribers. Begin forwarded message: Date: Thu, 30 Oct 2025 11:10:21 -0400 From: John McCue <jmccue@jmcunx.com> To: a1ex@dismail.de Cc: dillo-dev@mailman3.com Subject: Re: Dillo gopher plugin on OpenBSD issue [...] Somehow I missed it seeing there was a list. I found another issues with the gopher plugin on OpenBSD. The issue I am testing is with dpi.c. On OpenBSD, it has to do with how clang works on OpenBSD. The diffs are below. So far, with the changes to io.c and dpi.c, the plugin works fine on both OpenBSD and NetBSD. diff --git a/io.c b/io.c index 615f346..a10a0b3 100644 --- a/io.c +++ b/io.c @@ -1,3 +1,4 @@ +#include <sys/param.h> #include <string.h> #include <errno.h> #include <unistd.h> @@ -8,6 +9,12 @@ #include <netdb.h> #include <netinet/in.h> +#ifdef OpenBSD +#include <sys/socket.h> +#include <net/if.h> +#include <net/route.h> +#endif + #include "io.h" int read_all(int fd, unsigned char *buf, size_t len) { diff --git a/dpi.c b/dpi.c index 7b38800..52547f8 100644 --- a/dpi.c +++ b/dpi.c @@ -7,7 +7,7 @@ #include "io.h" static void check_auth() { - char buf[30]; + char buf[31]; int rc; char key[4], local_key[4]; char keys[128]; @@ -16,16 +16,16 @@ static void check_auth() { rc = read_all(STDIN_FILENO, buf, 29); if (rc < 0) err(1, "read auth"); buf[30] = '\0'; - rc = sscanf(buf, "<cmd='auth' msg='%4x' '>", key); + rc = sscanf(buf, "<cmd='auth' msg='%4x' '>", (unsigned int *) key); if (rc < 0) err(1, "auth: %.*s", 29, buf); if (rc < 1) errx(1, "auth: %.*s", 29, buf); home = getenv("HOME"); if (!home) home = "."; sz = read_file(keys, sizeof(keys), "%s/.dillo/dpid_comm_keys", home); if (sz < 0) err(1, "read dillo comm keys"); - rc = sscanf(keys, "%*d %4x' '>", local_key); - if (rc < 0) err(1, "comm key: %.*s", sz, keys); - if (rc < 1) errx(1, "comm key: %.*s", sz, keys); + rc = sscanf(keys, "%*d %4x' '>", (unsigned int *) local_key); + if (rc < 0) err(1, "comm key: %.*s", (int) sz, keys); + if (rc < 1) errx(1, "comm key: %.*s", (int) sz, keys); if (memcmp(key, local_key, 4)) errx(1, "wrong dillo key"); } @@ -38,7 +38,7 @@ static void get_url(char *url_buf, size_t url_len) { rc = read_all(STDIN_FILENO, buf, sizeof(buf)); if (rc < 0) err(1, "read open_url"); if (strncmp(buf, "<cmd='open_url' url='", 21)) { - err(1, "bad open_url cmd: %.*s", sizeof(buf), buf); + err(1, "bad open_url cmd: %.*s", (int) sizeof(buf), buf); } len = url_len; rc = read_some(STDIN_FILENO, url_buf, &len); @@ -48,7 +48,7 @@ static void get_url(char *url_buf, size_t url_len) { if (url_buf[i] == '\'' && url_buf[i+1] == ' ') break; } if (i > len-3 || strncmp(url_buf + i, "' '>", 4)) { - err(1, "bad url end: %.*s", len, url_buf); + err(1, "bad url end: %.*s", (int) len, url_buf); } url_buf[i] = '\0'; }
Hi Alex, John, On Thu, Oct 30, 2025 at 12:05:51PM +0000, a1ex@dismail.de wrote:
Hi,
I saw this issue on Reddit today pertaining to the Gopher plugin not working correctly on OpenBSD. It includes a fix (I haven't tested it):
https://eddrit.com/r/openbsd/comments/1oj3ljg/dillo_gopher_plugin_issue_work...
Thanks, I saw it as well. Nice frontend btw.
Date: Thu, 30 Oct 2025 11:10:21 -0400 From: John McCue <jmccue@jmcunx.com> To: a1ex@dismail.de Cc: dillo-dev@mailman3.com Subject: Re: Dillo gopher plugin on OpenBSD issue
[...]
Somehow I missed it seeing there was a list. I found another issues with the gopher plugin on OpenBSD.
The issue I am testing is with dpi.c. On OpenBSD, it has to do with how clang works on OpenBSD. The diffs are below.
I can reproduce many issues on Linux with `CC=clang make`. I'm getting a few more warnings that should be easy to solve.
So far, with the changes to io.c and dpi.c, the plugin works fine on both OpenBSD and NetBSD.
diff --git a/io.c b/io.c index 615f346..a10a0b3 100644 --- a/io.c +++ b/io.c @@ -1,3 +1,4 @@ +#include <sys/param.h> #include <string.h> #include <errno.h> #include <unistd.h> @@ -8,6 +9,12 @@ #include <netdb.h> #include <netinet/in.h>
+#ifdef OpenBSD
I don't think we need to handle OpenBSD differently, but instead make the code portable by targeting C and POSIX standards.
+#include <sys/socket.h>
This is always needed as we use socket(), but it should not be needed here as it would be included via <netinet/in.h>, from netinet_in.h(0P):
Inclusion of the <netinet/in.h> header may also make visible all symbols from <inttypes.h> and <sys/socket.h>
Not sure if OpenBSD follows this, otherwise can simply include it unconditionally.
+#include <net/if.h> +#include <net/route.h>
Needed?
+#endif +
Building with: % make CC=clang CFLAGS="-std=c11 -Wall -pedantic" Already reveals many problems. We can probably lower the C standard to C99. I don't have a machine with OpenBSD at hand, can you test if the build succeeds using the current master code in OpenBSD with these CFLAGS? It does on Linux: % git clone https://git.dillo-browser.org/plugins/gopher && cd gopher % make CC=clang CFLAGS="-Wall -std=c99 -D_POSIX_C_SOURCE=200112L" There are many warnings that should be fixed (as below), but the current includes should work otherwise. If not, does adding the extra + #include <sys/socket.h> line solves it?
#include "io.h"
int read_all(int fd, unsigned char *buf, size_t len) {
diff --git a/dpi.c b/dpi.c index 7b38800..52547f8 100644 --- a/dpi.c +++ b/dpi.c @@ -7,7 +7,7 @@ #include "io.h"
static void check_auth() { - char buf[30]; + char buf[31]; int rc; char key[4], local_key[4]; char keys[128]; @@ -16,16 +16,16 @@ static void check_auth() { rc = read_all(STDIN_FILENO, buf, 29); if (rc < 0) err(1, "read auth"); buf[30] = '\0'; - rc = sscanf(buf, "<cmd='auth' msg='%4x' '>", key); + rc = sscanf(buf, "<cmd='auth' msg='%4x' '>", (unsigned int *) key); if (rc < 0) err(1, "auth: %.*s", 29, buf);
The patch is badly mangled, better use `git send-patch` or attach it as a file.
if (rc < 1) errx(1, "auth: %.*s", 29, buf); home = getenv("HOME"); if (!home) home = "."; sz = read_file(keys, sizeof(keys), "%s/.dillo/dpid_comm_keys", home); if (sz < 0) err(1, "read dillo comm keys"); - rc = sscanf(keys, "%*d %4x' '>", local_key); - if (rc < 0) err(1, "comm key: %.*s", sz, keys); - if (rc < 1) errx(1, "comm key: %.*s", sz, keys); + rc = sscanf(keys, "%*d %4x' '>", (unsigned int *) local_key); + if (rc < 0) err(1, "comm key: %.*s", (int) sz, keys); + if (rc < 1) errx(1, "comm key: %.*s", (int) sz, keys); if (memcmp(key, local_key, 4)) errx(1, "wrong dillo key"); }
@@ -38,7 +38,7 @@ static void get_url(char *url_buf, size_t url_len) { rc = read_all(STDIN_FILENO, buf, sizeof(buf)); if (rc < 0) err(1, "read open_url"); if (strncmp(buf, "<cmd='open_url' url='", 21)) { - err(1, "bad open_url cmd: %.*s", sizeof(buf), buf); + err(1, "bad open_url cmd: %.*s", (int) sizeof(buf), buf); } len = url_len; rc = read_some(STDIN_FILENO, url_buf, &len); @@ -48,7 +48,7 @@ static void get_url(char *url_buf, size_t url_len) { if (url_buf[i] == '\'' && url_buf[i+1] == ' ') break; } if (i > len-3 || strncmp(url_buf + i, "' '>", 4)) { - err(1, "bad url end: %.*s", len, url_buf); + err(1, "bad url end: %.*s", (int) len, url_buf); } url_buf[i] = '\0'; }
Thanks!, Rodrigo.
Hi Rodrigo, Rodrigo Arias <rodarima@gmail.com> wrote:
I don't have a machine with OpenBSD at hand, can you test if the build succeeds using the current master code in OpenBSD with these CFLAGS? It does on Linux:
% git clone https://git.dillo-browser.org/plugins/gopher && cd gopher % make CC=clang CFLAGS= "-Wall -std=c99 -D_POSIX_C_SOURCE=200112L"
$ make CC=clang CFLAGS="-Wall -std=c99 -D_POSIX_C_SOURCE=200112L" clang -Wall -std=c99 -D_POSIX_C_SOURCE=200112L -I/usr/local/include -I/usr/X11R6/include -c io.c io.c:84:20: error: use of undeclared identifier 'AF_UNSPEC' 84 | hints.ai_family = AF_UNSPEC; | ^ io.c:95:8: warning: call to undeclared function 'socket'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 95 | fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); | ^ io.c:97:7: warning: call to undeclared function 'connect'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 97 | if (connect(fd, rp->ai_addr, rp->ai_addrlen) == 0) break; | ^ 2 warnings and 1 error generated.
There are many warnings that should be fixed (as below), but the current includes should work otherwise. If not, does adding the extra
+ #include <sys/socket.h>
line solves it?
Looks better, now we get this: $ make CC=clang CFLAGS="-Wall -std=c99 -D_POSIX_C_SOURCE=200112L" clang -Wall -std=c99 -D_POSIX_C_SOURCE=200112L -I/usr/local/include -I/usr/X11R6/include -c io.c clang -Wall -std=c99 -D_POSIX_C_SOURCE=200112L -I/usr/local/include -I/usr/X11R6/include -c dpi.c dpi.c:19:47: warning: format specifies type 'unsigned int *' but the argument has type 'char *' [-Wformat] 19 | rc = sscanf(buf, "<cmd='auth' msg='%4x' '>", key); | ~~~ ^~~ | %3s dpi.c:26:35: warning: format specifies type 'unsigned int *' but the argument has type 'char *' [-Wformat] 26 | rc = sscanf(keys, "%*d %4x' '>", local_key); | ~~~ ^~~~~~~~~ | %3s dpi.c:27:34: warning: field precision should have type 'int', but argument has type 'ssize_t' (aka 'long') [-Wformat] 27 | if (rc < 0) err(1, "comm key: %.*s", sz, keys); | ~~^~ ~~ dpi.c:28:35: warning: field precision should have type 'int', but argument has type 'ssize_t' (aka 'long') [-Wformat] 28 | if (rc < 1) errx(1, "comm key: %.*s", sz, keys); | ~~^~ ~~ dpi.c:18:2: warning: array index 30 is past the end of the array (that has type 'char[30]') [-Warray-bounds] 18 | buf[30] = '\0'; | ^ ~~ dpi.c:10:2: note: array 'buf' declared here 10 | char buf[30]; | ^ dpi.c:41:31: warning: field precision should have type 'int', but argument has type 'unsigned long' [-Wformat] 41 | err(1, "bad open_url cmd: %.*s", sizeof(buf), buf); | ~~^~ ~~~~~~~~~~~ dpi.c:51:26: warning: field precision should have type 'int', but argument has type 'size_t' (aka 'unsigned long') [-Wformat] 51 | err(1, "bad url end: %.*s", len, url_buf); | ~~^~ ~~~ 7 warnings generated. Regards, Alex
participants (2)
-
a1ex@dismail.de -
Rodrigo Arias