2024-12-13 04:41 UTC

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0002824Buildsystem[All Projects] Generalpublic2024-11-11 12:08
ReporterJoão 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
StatusnewResolutionopen 
PlatformOSGNU/HurdOS Version
Summary0002824: Porting to GNU/Hurd
DescriptionNetsurf 3.10 does not build on GNU/Hurd due to 2 documented issues:
GNU/Hurd uses the mach kernel but is not Apple and can use function clock_gettime()
https://www.gnu.org/software/hurd/hurd/porting/guidelines.html#mach_darwin

The macro PATH_MAX is not defined in POSIX and is not present in GNU/Hurd
https://www.gnu.org/software/hurd/hurd/porting/guidelines.html#PATH_MAX_tt_MAX_PATH_tt_MAXPATHL

The attached patch addresses these two issues. For the latter case, the string size is allocated dynamically using functions of the asprinf() family and realpath() called with the NULL argument. I don't know if these functions are present and work as intended on all platforms that Netsurf builds on. If this patch creates problems for other OS, would you consider using the Gnulib functions?
https://www.gnu.org/software/gnulib/manual/html_node/asprintf.html
https://www.gnu.org/software/gnulib/manual/html_node/realpath.html

The patch was created against version 3.10 on Debian.

With this patch, the functions filepath_find() and filepath_sfind() have become pretty much equivalent. I have not suppressed either to keep the patch minimal and to let you decide what you would like to do.
TagsNo tags attached.
Fixed in CI build #
Reported in CI build #
Attached Files
  • patch file icon fix_ftbfs_hurd.patch (13,179 bytes) 2021-06-05 21:39 -
    --- netsurf-3.10.orig/libnsutils/src/time.c
    +++ netsurf-3.10/libnsutils/src/time.c
    @@ -16,11 +16,11 @@
     #include <stdlib.h>
     #include <unistd.h>
     
    -#if (defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && (defined _POSIX_MONOTONIC_CLOCK)) || defined(__OpenBSD__)
    +#if (defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && (defined _POSIX_MONOTONIC_CLOCK)) || defined(__OpenBSD__) || defined(__GNU__)
     #include <time.h>
     #elif defined(__riscos)
     #include <oslib/os.h>
    -#elif defined(__MACH__)
    +#elif defined(__MACH__) && defined(__APPLE__)
     #include <mach/mach.h>
     #include <mach/clock.h>
     #include <mach/mach_time.h>
    @@ -41,7 +41,7 @@ nsuerror nsu_getmonotonic_ms(uint64_t *c
         uint64_t current;
         static uint64_t prev = 0; /* previous time so we never go backwards */
     
    -#if (defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && (defined _POSIX_MONOTONIC_CLOCK)) || defined(__OpenBSD__)
    +#if (defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && (defined _POSIX_MONOTONIC_CLOCK)) || defined(__OpenBSD__) || defined(__GNU__)
         struct timespec tp;
     
         clock_gettime(CLOCK_MONOTONIC, &tp);
    @@ -51,7 +51,7 @@ nsuerror nsu_getmonotonic_ms(uint64_t *c
     
         time = os_read_monotonic_time();
         current = time * 10;
    -#elif defined(__MACH__)
    +#elif defined(__MACH__) && defined(__APPLE__)
         clock_serv_t cclock;
         mach_timespec_t mts;
     
    --- netsurf-3.10.orig/netsurf/frontends/framebuffer/fetch.c
    +++ netsurf-3.10/netsurf/frontends/framebuffer/fetch.c
    @@ -48,13 +48,17 @@
      */
     static nsurl *get_resource_url(const char *path)
     {
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nsurl *url = NULL;
     
     	if (strcmp(path, "favicon.ico") == 0)
     		path = "favicon.png";
     
    -	netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
    +	netsurf_path_to_nsurl(filepath_sfind(respaths, &buf, path), &url);
    +        
    +        if (buf != NULL) {
    +		free(buf);
    +	}
     
     	return url;
     }
    --- netsurf-3.10.orig/netsurf/frontends/framebuffer/font_freetype.c
    +++ netsurf-3.10/netsurf/frontends/framebuffer/font_freetype.c
    @@ -120,15 +120,18 @@ fb_new_face(const char *option, const ch
             fb_faceid_t *newf;
             FT_Error error;
             FT_Face aface;
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     
             newf = calloc(1, sizeof(fb_faceid_t));
     
             if (option != NULL) {
                     newf->fontfile = strdup(option);
             } else {
    -		filepath_sfind(respaths, buf, fontname);
    +		filepath_sfind(respaths, &buf, fontname);
                     newf->fontfile = strdup(buf);
    +		if (buf != NULL) {
    +			free(buf);
    +		}
             }
     
             error = FTC_Manager_LookupFace(ft_cmanager, (FTC_FaceID)newf, &aface);
    --- netsurf-3.10.orig/netsurf/frontends/gtk/fetch.c
    +++ netsurf-3.10/netsurf/frontends/gtk/fetch.c
    @@ -249,14 +249,17 @@ const char *fetch_filetype(const char *u
     
     static nsurl *nsgtk_get_resource_url(const char *path)
     {
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nsurl *url = NULL;
     
     	/* favicon.ico -> favicon.png */
     	if (strcmp(path, "favicon.ico") == 0) {
     		nsurl_create("resource:favicon.png", &url);
     	} else {
    -		netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
    +		netsurf_path_to_nsurl(filepath_sfind(respaths, &buf, path), &url);
    +		if (buf != NULL) {
    +			free(buf);
    +		}
     	}
     
     	return url;
    --- netsurf-3.10.orig/netsurf/frontends/gtk/gui.c
    +++ netsurf-3.10/netsurf/frontends/gtk/gui.c
    @@ -335,8 +335,8 @@ static nserror nsgtk_add_named_icons_to_
      */
     static nserror nsgtk_init(int argc, char** argv, char **respath)
     {
    -	char buf[PATH_MAX];
    -	char *resource_filename;
    +	char *buf = NULL;
    +	char *resource_filename = NULL;
     	char *addr = NULL;
     	nsurl *url;
     	nserror res;
    @@ -407,8 +407,12 @@ static nserror nsgtk_init(int argc, char
     	browser_set_dpi(gdk_screen_get_resolution(gdk_screen_get_default()));
     	NSLOG(netsurf, INFO, "Set CSS DPI to %d", browser_get_dpi());
     
    -	filepath_sfinddef(respath, buf, "mime.types", "/etc/");
    +	filepath_sfinddef(respath, &buf, "mime.types", "/etc/");
     	gtk_fetch_filetype_init(buf);
    +	
    +	if (buf != NULL) {
    +		free(buf);
    +	}
     
     	save_complete_init();
     
    --- netsurf-3.10.orig/netsurf/frontends/monkey/fetch.c
    +++ netsurf-3.10/netsurf/frontends/monkey/fetch.c
    @@ -36,10 +36,13 @@ extern char **respaths;
     
     static nsurl *gui_get_resource_url(const char *path)
     {
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nsurl *url = NULL;
     
    -	netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
    +	netsurf_path_to_nsurl(filepath_sfind(respaths, &buf, path), &url);
    +	if (buf != NULL) {
    +		free(buf);
    +	}
     
     	return url;
     }
    --- netsurf-3.10.orig/netsurf/frontends/monkey/main.c
    +++ netsurf-3.10/netsurf/frontends/monkey/main.c
    @@ -379,7 +379,7 @@ main(int argc, char **argv)
     {
     	char *messages;
     	char *options;
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nserror ret;
     	struct netsurf_table monkey_table = {
     		.misc = &monkey_misc_table,
    @@ -441,8 +441,11 @@ main(int argc, char **argv)
     		die("NetSurf failed to initialise");
     	}
     
    -	filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
    +	filepath_sfinddef(respaths, &buf, "mime.types", "/etc/");
     	monkey_fetch_filetype_init(buf);
    +	if (buf != NULL) {
    +		free(buf);
    +	}
     
     	urldb_load(nsoption_charp(url_file));
     	urldb_load_cookies(nsoption_charp(cookie_file));
    --- netsurf-3.10.orig/netsurf/frontends/windows/fetch.c
    +++ netsurf-3.10/netsurf/frontends/windows/fetch.c
    @@ -76,10 +76,13 @@ static const char *fetch_filetype(const
      */
     static nsurl *nsw32_get_resource_url(const char *path)
     {
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nsurl *url = NULL;
     
    -	netsurf_path_to_nsurl(filepath_sfind(G_resource_pathv, buf, path), &url);
    +	netsurf_path_to_nsurl(filepath_sfind(G_resource_pathv, &buf, path), &url);
    +	if (buf != NULL) {
    +		free(buf);
    +	}
     
     	return url;
     }
    --- netsurf-3.10.orig/netsurf/frontends/windows/main.c
    +++ netsurf-3.10/netsurf/frontends/windows/main.c
    @@ -191,7 +191,11 @@ static nserror set_defaults(struct nsopt
     	if (res_len > 0) {
     		nsoption_setnull_charp(ca_bundle, strdup(buf));
     	} else {
    -		ptr = filepath_sfind(G_resource_pathv, buf, "ca-bundle.crt");
    +		if (buf != NULL) {
    +			free(buf);
    +			buf = NULL;
    +		}
    +		ptr = filepath_sfind(G_resource_pathv, &buf, "ca-bundle.crt");
     		if (ptr != NULL) {
     			nsoption_setnull_charp(ca_bundle, strdup(buf));
     		}
    @@ -204,6 +208,7 @@ static nserror set_defaults(struct nsopt
     	 * not available so use the obsolete method of user prodile
     	 * with downloads suffixed
     	 */
    +	buf = realloc(buf,buf_bytes_size);
     	buf[0] = '\0';
     
     	hres = SHGetFolderPath(NULL,
    --- netsurf-3.10.orig/netsurf/utils/filepath.c
    +++ netsurf-3.10/netsurf/utils/filepath.c
    @@ -24,6 +24,11 @@
      *  straightforward.
      */
     
    +/* This is needed by asprinf type of functions on GNU/Hurd*/
    +#if defined(__GNU__)
    +#define _GNU_SOURCE 1
    +#endif
    +
     #include <sys/types.h>
     #include <sys/stat.h>
     #include <stdarg.h>
    @@ -42,44 +47,43 @@
     #define MAX_RESPATH 128
     
     /* exported interface documented in filepath.h */
    -char *filepath_vsfindfile(char *str, const char *format, va_list ap)
    +char *filepath_vsfindfile(char **str, const char *format, va_list ap)
     {
    -	char *realpathname;
     	char *pathname;
     	int len;
     
    -	pathname = malloc(PATH_MAX);
    -	if (pathname == NULL)
    -		return NULL; /* unable to allocate memory */
    -
    -	len = vsnprintf(pathname, PATH_MAX, format, ap);
    -
    -	if ((len < 0) || (len >= PATH_MAX)) {
    -		/* error or output exceeded PATH_MAX length so
    -		 * operation is doomed to fail.
    -		 */
    -		free(pathname);
    +       if (str == NULL) {
     		return NULL;
    +	}
    +
    +	len = vasprintf(&pathname, format, ap);
    +
    +        if (len < 0) {
    +		return NULL; /* error in vasprintf */
     	}
     
    -	realpathname = realpath(pathname, str);
    +	*str = realpath(pathname, NULL);
     
    -	free(pathname);
    +	if (pathname != NULL) {
    +		free(pathname);
    +	}
     
    -	if (realpathname != NULL) {
    +	if (*str != NULL) {
     		/* sucessfully expanded pathname */
    -		if (access(realpathname, R_OK) != 0) {
    +		if (access(*str, R_OK) != 0) {
     			/* unable to read the file */
    +			free(*str);
    +			*str=NULL;
     			return NULL;
     		}
     	}
     
    -	return realpathname;
    +	return *str;
     }
     
     
     /* exported interface documented in filepath.h */
    -char *filepath_sfindfile(char *str, const char *format, ...)
    +char *filepath_sfindfile(char **str, const char *format, ...)
     {
     	va_list ap;
     	char *ret;
    @@ -105,8 +109,9 @@ char *filepath_findfile(const char *form
     	return ret;
     }
     
    +
     /* exported interface documented in filepath.h */
    -char *filepath_sfind(char **respathv, char *filepath, const char *filename)
    +char *filepath_sfind(char **respathv, char **filepath, const char *filename)
     {
     	int respathc = 0;
     
    @@ -115,7 +120,7 @@ char *filepath_sfind(char **respathv, ch
     
     	while (respathv[respathc] != NULL) {
     		if (filepath_sfindfile(filepath, "%s/%s", respathv[respathc], filename) != NULL) {
    -			return filepath;
    +			return *filepath;
     		}
     
     		respathc++;
    @@ -128,33 +133,23 @@ char *filepath_sfind(char **respathv, ch
     /* exported interface documented in filepath.h */
     char *filepath_find(char **respathv, const char *filename)
     {
    -	char *ret;
    -	char *filepath;
    +	char *filepath = NULL;
     
     	if ((respathv == NULL) || (respathv[0] == NULL))
     		return NULL;
     
    -	filepath = malloc(PATH_MAX);
    -	if (filepath == NULL)
    -		return NULL;
    -
    -	ret = filepath_sfind(respathv, filepath, filename);
    -
    -	if (ret == NULL)
    -		free(filepath);
    -
    -	return ret;
    +	return filepath_sfind(respathv, &filepath, filename);
     }
     
     
     /* exported interface documented in filepath.h */
     char *
     filepath_sfinddef(char **respathv,
    -		  char *filepath,
    +		  char **filepath,
     		  const char *filename,
     		  const char *def)
     {
    -	char t[PATH_MAX];
    +        char *t = NULL;
     	char *ret;
     
     	if ((respathv == NULL) || (respathv[0] == NULL) || (filepath == NULL))
    @@ -164,17 +159,22 @@ filepath_sfinddef(char **respathv,
     
     	if ((ret == NULL) && (def != NULL)) {
     		/* search failed, return the path specified */
    -		ret = filepath;
    +		ret = *filepath;
     		if (def[0] == '~') {
    -			snprintf(t, PATH_MAX, "%s/%s/%s", getenv("HOME"), def + 1, filename);
    +			asprintf(&t, "%s/%s/%s", getenv("HOME"), def + 1, filename);
     		} else {
    -			snprintf(t, PATH_MAX, "%s/%s", def, filename);
    +			asprintf(&t, "%s/%s", def, filename);
     		}
     		if (realpath(t, ret) == NULL) {
    -			strncpy(ret, t, PATH_MAX);
    +			strncpy(ret, t, strlen(ret));
     		}
     
     	}
    +
    +	if (t != NULL) {
    +		free(t);
    +	}
    +
     	return ret;
     }
     
    --- netsurf-3.10.orig/netsurf/utils/filepath.h
    +++ netsurf-3.10/netsurf/utils/filepath.h
    @@ -35,14 +35,14 @@
      * normalised path is placed in str and a pointer to str returned
      * otherwise NULL is returned. The string in str is always modified.
      *
    - * @param str A buffer to contain the normalised file name must be at
    - *            least PATH_MAX bytes long.
    + * @param str A pointer to the normalised file name. Starts at NULL and
    + *        is allocate within the function. Must be freed by caller.
      * @param format A printf format for the filename.
      * @param ap The list of arguments for the format.
      * @return A pointer to the expanded filename or NULL if the file is
      *         not present or accessible.
      */
    -char *filepath_vsfindfile(char *str, const char *format, va_list ap);
    +char *filepath_vsfindfile(char **str, const char *format, va_list ap);
     
     
     /**
    @@ -50,7 +50,7 @@ char *filepath_vsfindfile(char *str, con
      *
      * Similar to vsfindfile but takes variadic (printf like) parameters
      */
    -char *filepath_sfindfile(char *str, const char *format, ...);
    +char *filepath_sfindfile(char **str, const char *format, ...);
     
     
     /**
    @@ -70,18 +70,19 @@ char *filepath_findfile(const char *form
      * can be found in any of the resource paths.
      *
      * \param respathv The resource path vector to iterate.
    - * \param filepath The buffer to place the result in.
    + * \param filepath A NULL double pointer that will be allocated and
    + *                 point to the result. Needs to be freed by caller.
      * \param filename The filename of the resource to search for.
      * \return A pointer to filepath if a target is found or NULL if not.
      */
    -char *filepath_sfind(char **respathv, char *filepath, const char *filename);
    +char *filepath_sfind(char **respathv, char **filepath, const char *filename);
     
     
     /**
      * Searches an array of resource paths for a file.
      *
    - * Similar to filepath_sfind except it allocates its own storage for
    - * the returned string. The caller must free this sorage.
    + * Similar to filepath_sfind except the result double pointer does not need
    + * to be passed as argument or freed. The caller must free this sorage.
      */
     char *filepath_find(char **respathv, const char *filename);
     
    @@ -95,12 +96,12 @@ char *filepath_find(char **respathv, con
      * path and the filename.
      *
      * \param respathv The resource path vector to iterate.
    - * \param filepath The buffer to place the result in. Must have space for PATH_MAX bytes.
    + * \param filepath will be allocated and give the result.
      * \param filename The filename of the resource to search for.
      * \param def The default path to use
      * \return A pointer to filepath if a target is found or the default if not
      */
    -char *filepath_sfinddef(char **respathv, char *filepath, const char *filename,
    +char *filepath_sfinddef(char **respathv, char **filepath, const char *filename,
     		const char *def);
     
     
    
    patch file icon fix_ftbfs_hurd.patch (13,179 bytes) 2021-06-05 21:39 +
  • ? file icon fix_ftbfs_hurd.patch2 (13,346 bytes) 2021-07-05 15:27
  • patch file icon fix-ftbfs-hurd.v3.patch (11,898 bytes) 2024-08-14 08:24 -
    --- netsurf-3.11.orig/netsurf/frontends/framebuffer/fetch.c
    +++ netsurf-3.11/netsurf/frontends/framebuffer/fetch.c
    @@ -48,13 +48,16 @@
      */
     static nsurl *get_resource_url(const char *path)
     {
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nsurl *url = NULL;
     
     	if (strcmp(path, "favicon.ico") == 0)
     		path = "favicon.png";
     
    -	netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
    +	buf = filepath_find(respaths, path);
    +	netsurf_path_to_nsurl(buf, &url);
    + 
    +	free(buf);
     
     	return url;
     }
    --- netsurf-3.11.orig/netsurf/frontends/framebuffer/font_freetype.c
    +++ netsurf-3.11/netsurf/frontends/framebuffer/font_freetype.c
    @@ -120,15 +120,16 @@ fb_new_face(const char *option, const ch
             fb_faceid_t *newf;
             FT_Error error;
             FT_Face aface;
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     
             newf = calloc(1, sizeof(fb_faceid_t));
     
             if (option != NULL) {
                     newf->fontfile = strdup(option);
             } else {
    -		filepath_sfind(respaths, buf, fontname);
    +		buf = filepath_find(respaths, fontname);
                     newf->fontfile = strdup(buf);
    +		free(buf);
             }
     
             error = FTC_Manager_LookupFace(ft_cmanager, (FTC_FaceID)newf, &aface);
    --- netsurf-3.11.orig/netsurf/frontends/gtk/fetch.c
    +++ netsurf-3.11/netsurf/frontends/gtk/fetch.c
    @@ -250,14 +250,16 @@ const char *fetch_filetype(const char *u
     
     static nsurl *nsgtk_get_resource_url(const char *path)
     {
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nsurl *url = NULL;
     
     	/* favicon.ico -> favicon.png */
     	if (strcmp(path, "favicon.ico") == 0) {
     		nsurl_create("resource:favicon.png", &url);
     	} else {
    -		netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
    +		buf = filepath_find(respaths, path);
    +		netsurf_path_to_nsurl(buf, &url);
    +		free(buf);
     	}
     
     	return url;
    --- netsurf-3.11.orig/netsurf/frontends/gtk/gui.c
    +++ netsurf-3.11/netsurf/frontends/gtk/gui.c
    @@ -909,8 +909,8 @@ static nserror nsgtk_add_named_icons_to_
      */
     static nserror nsgtk_setup(int argc, char** argv, char **respath)
     {
    -	char buf[PATH_MAX];
    -	char *resource_filename;
    +	char *buf = NULL;
    +	char *resource_filename = NULL;
     	char *addr = NULL;
     	nsurl *url;
     	nserror res;
    @@ -986,8 +986,9 @@ static nserror nsgtk_setup(int argc, cha
     		.pma = true,
     	});
     
    -	filepath_sfinddef(respath, buf, "mime.types", "/etc/");
    +	buf = filepath_sfinddef(respath, "mime.types", "/etc/");
     	gtk_fetch_filetype_init(buf);
    +	free(buf);
     
     	save_complete_init();
     
    --- netsurf-3.11.orig/netsurf/frontends/monkey/fetch.c
    +++ netsurf-3.11/netsurf/frontends/monkey/fetch.c
    @@ -36,10 +36,12 @@ extern char **respaths;
     
     static nsurl *gui_get_resource_url(const char *path)
     {
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nsurl *url = NULL;
     
    -	netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
    +	buf = filepath_find(respaths, path);
    +	netsurf_path_to_nsurl(buf, &url);
    +	free(buf);
     
     	return url;
     }
    --- netsurf-3.11.orig/netsurf/frontends/monkey/main.c
    +++ netsurf-3.11/netsurf/frontends/monkey/main.c
    @@ -390,7 +390,7 @@ main(int argc, char **argv)
     {
     	char *messages;
     	char *options;
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nserror ret;
     	struct netsurf_table monkey_table = {
     		.misc = &monkey_misc_table,
    @@ -452,8 +452,9 @@ main(int argc, char **argv)
     		die("NetSurf failed to initialise");
     	}
     
    -	filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
    +	buf = filepath_sfinddef(respaths, "mime.types", "/etc/");
     	monkey_fetch_filetype_init(buf);
    +	free(buf);
     
     	urldb_load(nsoption_charp(url_file));
     	urldb_load_cookies(nsoption_charp(cookie_file));
    --- netsurf-3.11.orig/netsurf/frontends/windows/fetch.c
    +++ netsurf-3.11/netsurf/frontends/windows/fetch.c
    @@ -76,10 +76,12 @@ static const char *fetch_filetype(const
      */
     static nsurl *nsw32_get_resource_url(const char *path)
     {
    -	char buf[PATH_MAX];
    +	char *buf = NULL;
     	nsurl *url = NULL;
     
    -	netsurf_path_to_nsurl(filepath_sfind(G_resource_pathv, buf, path), &url);
    +	buf = filepath_find(G_resource_pathv, path);
    +	netsurf_path_to_nsurl(buf, &url);
    +	free(buf);
     
     	return url;
     }
    --- netsurf-3.11.orig/netsurf/frontends/windows/main.c
    +++ netsurf-3.11/netsurf/frontends/windows/main.c
    @@ -171,12 +171,13 @@ static nserror set_defaults(struct nsopt
     	DWORD buf_bytes_size = sizeof(TCHAR) * buf_tchar_size;
     	char *ptr = NULL;
     	char *buf;
    +	char *buftest;
     	char *fname;
     	HRESULT hres;
     	char dldir[] = "Downloads";
     
     	buf = malloc(buf_bytes_size);
    -	if (buf== NULL) {
    +	if (buf == NULL) {
     		return NSERROR_NOMEM;
     	}
     	buf[0] = '\0';
    @@ -191,8 +192,9 @@ static nserror set_defaults(struct nsopt
     	if (res_len > 0) {
     		nsoption_setnull_charp(ca_bundle, strdup(buf));
     	} else {
    -		ptr = filepath_sfind(G_resource_pathv, buf, "ca-bundle.crt");
    -		if (ptr != NULL) {
    +		free(buf);
    +		buf = filepath_find(G_resource_pathv, "ca-bundle.crt");
    +		if (buf != NULL) {
     			nsoption_setnull_charp(ca_bundle, strdup(buf));
     		}
     	}
    @@ -204,6 +206,12 @@ static nserror set_defaults(struct nsopt
     	 * not available so use the obsolete method of user prodile
     	 * with downloads suffixed
     	 */
    +	buftest = realloc(buf, buf_bytes_size);
    +	if (buftest == NULL) {
    +		free(buf);
    +		return NSERROR_BAD_SIZE;
    +	}
    +	buf = buftest
     	buf[0] = '\0';
     
     	hres = SHGetFolderPath(NULL,
    --- netsurf-3.11.orig/netsurf/utils/Makefile
    +++ netsurf-3.11/netsurf/utils/Makefile
    @@ -24,3 +24,6 @@ S_UTILS := \
     	utils.c
     
     S_UTILS := $(addprefix utils/,$(S_UTILS))
    +
    +#This is needed by asprintf type of functions in utils/filepath.c
    +CFLAGS += -D_GNU_SOURCE
    --- netsurf-3.11.orig/netsurf/utils/filepath.c
    +++ netsurf-3.11/netsurf/utils/filepath.c
    @@ -42,27 +42,18 @@
     #define MAX_RESPATH 128
     
     /* exported interface documented in filepath.h */
    -char *filepath_vsfindfile(char *str, const char *format, va_list ap)
    +char *filepath_vsfindfile(const char *format, va_list ap)
     {
     	char *realpathname;
     	char *pathname;
     	int len;
     
    -	pathname = malloc(PATH_MAX);
    -	if (pathname == NULL)
    -		return NULL; /* unable to allocate memory */
    -
    -	len = vsnprintf(pathname, PATH_MAX, format, ap);
    -
    -	if ((len < 0) || (len >= PATH_MAX)) {
    -		/* error or output exceeded PATH_MAX length so
    -		 * operation is doomed to fail.
    -		 */
    -		free(pathname);
    -		return NULL;
    -	}
    +	len = vasprintf(&pathname, format, ap);
    +
    +        if (len < 0) 
    +		return NULL; /* error in vasprintf */
     
    -	realpathname = realpath(pathname, str);
    +	realpathname = realpath(pathname, NULL);
     
     	free(pathname);
     
    @@ -70,6 +61,7 @@ char *filepath_vsfindfile(char *str, con
     		/* sucessfully expanded pathname */
     		if (access(realpathname, R_OK) != 0) {
     			/* unable to read the file */
    +			free(realpathname);
     			return NULL;
     		}
     	}
    @@ -79,13 +71,13 @@ char *filepath_vsfindfile(char *str, con
     
     
     /* exported interface documented in filepath.h */
    -char *filepath_sfindfile(char *str, const char *format, ...)
    +char *filepath_findfile(const char *format, ...)
     {
     	va_list ap;
     	char *ret;
     
     	va_start(ap, format);
    -	ret = filepath_vsfindfile(str, format, ap);
    +	ret = filepath_vsfindfile(format, ap);
     	va_end(ap);
     
     	return ret;
    @@ -93,28 +85,17 @@ char *filepath_sfindfile(char *str, cons
     
     
     /* exported interface documented in filepath.h */
    -char *filepath_findfile(const char *format, ...)
    -{
    -	char *ret;
    -	va_list ap;
    -
    -	va_start(ap, format);
    -	ret = filepath_vsfindfile(NULL, format, ap);
    -	va_end(ap);
    -
    -	return ret;
    -}
    -
    -/* exported interface documented in filepath.h */
    -char *filepath_sfind(char **respathv, char *filepath, const char *filename)
    +char *filepath_find(char **respathv, const char *filename)
     {
     	int respathc = 0;
    +	char *filepath = NULL;
     
     	if ((respathv == NULL) || (respathv[0] == NULL) || (filepath == NULL))
     		return NULL;
     
     	while (respathv[respathc] != NULL) {
    -		if (filepath_sfindfile(filepath, "%s/%s", respathv[respathc], filename) != NULL) {
    +		filepath = filepath_findfile("%s/%s", respathv[respathc], filename);
    +		if (filepath != NULL) {
     			return filepath;
     		}
     
    @@ -126,55 +107,33 @@ char *filepath_sfind(char **respathv, ch
     
     
     /* exported interface documented in filepath.h */
    -char *filepath_find(char **respathv, const char *filename)
    -{
    -	char *ret;
    -	char *filepath;
    -
    -	if ((respathv == NULL) || (respathv[0] == NULL))
    -		return NULL;
    -
    -	filepath = malloc(PATH_MAX);
    -	if (filepath == NULL)
    -		return NULL;
    -
    -	ret = filepath_sfind(respathv, filepath, filename);
    -
    -	if (ret == NULL)
    -		free(filepath);
    -
    -	return ret;
    -}
    -
    -
    -/* exported interface documented in filepath.h */
     char *
     filepath_sfinddef(char **respathv,
    -		  char *filepath,
     		  const char *filename,
     		  const char *def)
     {
    -	char t[PATH_MAX];
    +	char *t = NULL;
     	char *ret;
     
    -	if ((respathv == NULL) || (respathv[0] == NULL) || (filepath == NULL))
    +	if ((respathv == NULL) || (respathv[0] == NULL))
     		return NULL;
     
    -	ret = filepath_sfind(respathv, filepath, filename);
    +	ret = filepath_find(respathv, filename);
     
     	if ((ret == NULL) && (def != NULL)) {
     		/* search failed, return the path specified */
    -		ret = filepath;
     		if (def[0] == '~') {
    -			snprintf(t, PATH_MAX, "%s/%s/%s", getenv("HOME"), def + 1, filename);
    +			asprintf(&t, "%s/%s/%s", getenv("HOME"), def + 1, filename);
     		} else {
    -			snprintf(t, PATH_MAX, "%s/%s", def, filename);
    -		}
    -		if (realpath(t, ret) == NULL) {
    -			strncpy(ret, t, PATH_MAX);
    +			asprintf(&t, "%s/%s", def, filename);
     		}
    -
    +		ret = realpath(t, NULL);
    +		if (ret == NULL)
    +			ret = t;
    +		else 
    +			free(t);
     	}
    +
     	return ret;
     }
     
    --- netsurf-3.11.orig/netsurf/utils/filepath.h
    +++ netsurf-3.11/netsurf/utils/filepath.h
    @@ -35,14 +35,12 @@
      * normalised path is placed in str and a pointer to str returned
      * otherwise NULL is returned. The string in str is always modified.
      *
    - * @param str A buffer to contain the normalised file name must be at
    - *            least PATH_MAX bytes long.
      * @param format A printf format for the filename.
      * @param ap The list of arguments for the format.
      * @return A pointer to the expanded filename or NULL if the file is
      *         not present or accessible.
      */
    -char *filepath_vsfindfile(char *str, const char *format, va_list ap);
    +char *filepath_vsfindfile(const char *format, va_list ap);
     
     
     /**
    @@ -50,15 +48,6 @@ char *filepath_vsfindfile(char *str, con
      *
      * Similar to vsfindfile but takes variadic (printf like) parameters
      */
    -char *filepath_sfindfile(char *str, const char *format, ...);
    -
    -
    -/**
    - * Create a normalised file name.
    - *
    - * Similar to sfindfile but allocates its own storage for the
    - * returned string. The caller must free this sorage.
    - */
     char *filepath_findfile(const char *format, ...);
     
     
    @@ -70,19 +59,9 @@ char *filepath_findfile(const char *form
      * can be found in any of the resource paths.
      *
      * \param respathv The resource path vector to iterate.
    - * \param filepath The buffer to place the result in.
      * \param filename The filename of the resource to search for.
      * \return A pointer to filepath if a target is found or NULL if not.
      */
    -char *filepath_sfind(char **respathv, char *filepath, const char *filename);
    -
    -
    -/**
    - * Searches an array of resource paths for a file.
    - *
    - * Similar to filepath_sfind except it allocates its own storage for
    - * the returned string. The caller must free this sorage.
    - */
     char *filepath_find(char **respathv, const char *filename);
     
     
    @@ -95,12 +74,11 @@ char *filepath_find(char **respathv, con
      * path and the filename.
      *
      * \param respathv The resource path vector to iterate.
    - * \param filepath The buffer to place the result in. Must have space for PATH_MAX bytes.
      * \param filename The filename of the resource to search for.
      * \param def The default path to use
      * \return A pointer to filepath if a target is found or the default if not
      */
    -char *filepath_sfinddef(char **respathv, char *filepath, const char *filename,
    +char *filepath_sfinddef(char **respathv, const char *filename,
     		const char *def);
     
     
    
    patch file icon fix-ftbfs-hurd.v3.patch (11,898 bytes) 2024-08-14 08:24 +

-Relationships
+Relationships

-Notes
John Scott

~0002344

John Scott (reporter)

Note that, since the pathlength is unlimited on GNU/Linux systems as well, it's technically a bug and a POSIX violation that PATH_MAX is defined there in the first place. Hence fixing the reliance on the definition of PATH_MAX is beneficial not just to enable builds on GNU/Hurd, but for correctness on any system with unlimited path lengths.
João

~0002345

João (reporter)

Uploading an updated patch after discussion in the debian-hurd mailing list
https://lists.debian.org/debian-hurd/2021/06/msg00006.html
João

~0002466

João (reporter)

Refresh patch to apply to version 3.11.
This bug is classified under Project "Buildsystem", which is probably incorrect, but I don't see how to change it. I don't know if this is causing lack of attention to this bug report.
+Notes

-Issue History
Date Modified Username Field Change
2021-06-05 21:39 João New Issue
2021-06-05 21:39 João File Added: fix_ftbfs_hurd.patch
2021-06-29 19:31 John Scott Note Added: 0002344
2021-07-05 15:27 João File Added: fix_ftbfs_hurd.patch2
2021-07-05 15:27 João Note Added: 0002345
2024-08-14 08:24 João File Added: fix-ftbfs-hurd.v3.patch
2024-08-14 08:24 João Note Added: 0002466
+Issue History