Bug#1076285: schism: Drop using PATH_MAX on non-Windows platforms
Package: schism
Version: 2:20240614-1
Tags: patch
The current source have a few artificial path limitations using
PATH_MAX. In addition to being a latent problem on any unix platforms
where the file system max do not match the hardcoded PATH_MAX, this also
break the build on GNU Hurd.
I just created a patch to drop this limit on non-Windows machines,
submitted upstream as
<URL: https://github.com/schismtracker/schismtracker/pull/493 >, the
patch is attached here as
0001-Drop-use-of-PATH_MAX-on-non-Windows-platforms.patch. I've also
created a patch relative to the git edition on salsa, attached as
1000-gnu-hurd-path-max.patch.
Please consider including it in Debian.
--
Happy hacking
Petter Reinholdtsen
Description: <short summary of the patch>
TODO: Put a short summary on the line above and replace this paragraph
with a longer explanation of this change. Complete the meta-information
with other relevant fields (see below for details). To make it easier, the
information below has been extracted from the changelog. Adjust it or drop
it.
.
schism (2:20240614-1) unstable; urgency=medium
.
* New upstream version 20240614
Author: Dennis Braun <snd@debian.org>
---
The information above should follow the Patch Tagging Guidelines, please
checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:
Origin: (upstream|backport|vendor|other), (<patch-url>|commit:<commit-id>)
Bug: <upstream-bugtracker-url>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: (no|not-needed|<patch-forwarded-url>)
Applied-Upstream: <version>, (<commit-url>|commit:<commid-id>)
Reviewed-By: <name and email of someone who approved/reviewed the patch>
Last-Update: 2024-07-13
Index: schism-salsa/schism/util.c
===================================================================
--- schism-salsa.orig/schism/util.c 2024-07-13 18:14:28.238021045 +0200
+++ schism-salsa/schism/util.c 2024-07-13 18:39:56.626351661 +0200
@@ -617,10 +617,10 @@
/* 0 = success, !0 = failed (check errno) */
int make_backup_file(const char *filename, int numbered)
{
- char buf[PATH_MAX];
+ int ret = 0;
+ char *buf = malloc(strlen(filename) + 16);
- /* ensure plenty of room to breathe */
- if (strlen(filename) > PATH_MAX - 16) {
+ if (NULL == buf) {
errno = ENAMETOOLONG;
return -1;
}
@@ -628,16 +628,19 @@
if (numbered) {
/* If some crazy person needs more than 65536 backup files,
they probably have more serious issues to tend to. */
- int n = 1, ret;
+ int n = 1;
do {
sprintf(buf, "%s.%d~", filename, n++);
ret = rename_file(filename, buf, 0);
} while (ret != 0 && errno == EEXIST && n < 65536);
+ free(buf);
return ret;
} else {
strcpy(buf, filename);
strcat(buf, "~");
- return rename_file(filename, buf, 1);
+ ret = rename_file(filename, buf, 1);
+ free(buf);
+ return ret;
}
}
@@ -783,11 +786,22 @@
if (_wgetcwd(buf, PATH_MAX) && !charset_iconv((uint8_t*)buf, &buf_utf8, CHARSET_WCHAR_T, CHARSET_UTF8))
return (char*)buf_utf8;
#else
- char buf[PATH_MAX + 1] = {'\0'};
+ /* Double the buffer size until getcwd() succeed or we run out
+ of memory. Not using get_current_dir_name() and
+ getcwd(NULL, n) to only use methods defined by POSIX. */
+ size_t n = 1024;
+ char *buf = malloc(n);
+ while (buf && NULL == getcwd(buf, n)) {
+ n *= 2;
+ char *newbuf = realloc(buf, n);
+ if (NULL == newbuf)
+ break;
+ buf = newbuf;
+ }
/* hmm. fall back to the current dir */
- if (getcwd(buf, PATH_MAX))
- return str_dup(buf);
+ if (buf)
+ return buf;
#endif
return str_dup(".");
}
>From 1c78ebc049131fe8d4a2aeaceef4bc53fee41656 Mon Sep 17 00:00:00 2001
From: Petter Reinholdtsen <pere@hungry.com>
Date: Sat, 13 Jul 2024 18:47:31 +0200
Subject: [PATCH] Drop use of PATH_MAX on non-Windows platforms.
There is no need to hardcode a maximum size limit for home directory path nor
backup file name paths, and dropping the artificial limit get the source building
on GNU Hurd.
---
schism/util.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/schism/util.c b/schism/util.c
index cbf70f56..967528ce 100644
--- a/schism/util.c
+++ b/schism/util.c
@@ -617,10 +617,10 @@ int get_num_lines(const char *text)
/* 0 = success, !0 = failed (check errno) */
int make_backup_file(const char *filename, int numbered)
{
- char buf[PATH_MAX];
+ int ret = 0;
+ char *buf = malloc(strlen(filename) + 16);
- /* ensure plenty of room to breathe */
- if (strlen(filename) > PATH_MAX - 16) {
+ if (NULL == buf) {
errno = ENAMETOOLONG;
return -1;
}
@@ -628,16 +628,19 @@ int make_backup_file(const char *filename, int numbered)
if (numbered) {
/* If some crazy person needs more than 65536 backup files,
they probably have more serious issues to tend to. */
- int n = 1, ret;
+ int n = 1;
do {
sprintf(buf, "%s.%d~", filename, n++);
ret = rename_file(filename, buf, 0);
} while (ret != 0 && errno == EEXIST && n < 65536);
+ free(buf);
return ret;
} else {
strcpy(buf, filename);
strcat(buf, "~");
- return rename_file(filename, buf, 1);
+ ret = rename_file(filename, buf, 1);
+ free(buf);
+ return ret;
}
}
@@ -783,10 +786,22 @@ char *get_current_directory(void)
if (_wgetcwd(buf, PATH_MAX) && !charset_iconv((uint8_t*)buf, &buf_utf8, CHARSET_WCHAR_T, CHARSET_UTF8))
return (char*)buf_utf8;
#else
- char buf[PATH_MAX + 1] = {'\0'};
-
- if (getcwd(buf, PATH_MAX))
- return str_dup(buf);
+ /* Double the buffer size until getcwd() succeed or we run out
+ of memory. Not using get_current_dir_name() and
+ getcwd(NULL, n) to only use methods defined by POSIX. */
+ size_t n = 1024;
+ char *buf = malloc(n);
+ while (buf && NULL == getcwd(buf, n)) {
+ n *= 2;
+ char *newbuf = realloc(buf, n);
+ if (NULL == newbuf)
+ break;
+ buf = newbuf;
+ }
+
+
+ if (buf)
+ return buf;
#endif
return str_dup(".");
}
--
2.39.2
Reply to: