Bug 74313 - [patch] Fix build on Hurd without PATH_MAX
Summary: [patch] Fix build on Hurd without PATH_MAX
Status: RESOLVED FIXED
Alias: None
Product: Spice
Classification: Unclassified
Component: server (show other bugs)
Version: unspecified
Hardware: x86 (IA32) other
: medium normal
Assignee: Spice Bug List
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-01 11:02 UTC by Petter Reinholdtsen
Modified: 2015-03-10 22:14 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Petter Reinholdtsen 2014-02-01 11:02:24 UTC
The following patch fixes the server build on Hurd, where PATH_MAX is not available.  With the fix, all the server part of spice builds on Hurd.

I'm also looking at the client part, but it require thread features I do not
yet know on Hurd.

--- spice-0.12.4.orig/server/tests/test_display_base.c
+++ spice-0.12.4/server/tests/test_display_base.c
@@ -87,12 +87,13 @@ static void regression_test(void)
 
     pid = fork();
     if (pid == 0) {
-        char buf[PATH_MAX];
+        char *buf = malloc(strlen(getenv("PATH"))+6);
         char *argp[] = {NULL};
         char *envp[] = {buf, NULL};
 
         snprintf(buf, sizeof(buf), "PATH=%s", getenv("PATH"));
         execve("regression_test.py", argp, envp);
+        free(buf); /* In case the exec fail */
     } else if (pid > 0) {
         return;
     }

-- 
Happy hacking
Petter Reinholdtsen
Comment 1 Emilio Pozuelo Monfort 2014-02-01 11:40:47 UTC
         snprintf(buf, sizeof(buf), "PATH=%s", getenv("PATH"));

Won't this just write up to sizeof(buf) bytes, that is, up to sizeof(char *), which is normally 4 or 8 bytes? I think you want to change sizeof(buf) with
strlen(getenv("PATH"))+6 (ideally caching the result in a new len variable to avoid doing that calculation twice).
Comment 2 Petter Reinholdtsen 2014-02-01 12:31:02 UTC
You are right.  Sorry.  I got so excided when I got it building I forgot to update the snprintf() call too.

Here is an updated patch.

--- spice-0.12.4.orig/server/tests/test_display_base.c
+++ spice-0.12.4/server/tests/test_display_base.c
@@ -87,12 +87,14 @@ static void regression_test(void)
 
     pid = fork();
     if (pid == 0) {
-        char buf[PATH_MAX];
+        int buflen = strlen(getenv("PATH"))+6;
+        char *buf = malloc(buflen);
         char *argp[] = {NULL};
         char *envp[] = {buf, NULL};
 
-        snprintf(buf, sizeof(buf), "PATH=%s", getenv("PATH"));
+        snprintf(buf, buflen, "PATH=%s", getenv("PATH"));
         execve("regression_test.py", argp, envp);
+        free(buf); /* In case the exec fail */
     } else if (pid > 0) {
         return;
     }
Comment 3 Christophe Fergeau 2014-02-03 09:01:19 UTC
I'd just add a
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
somewhere after all the #includes at the top of the file.
Comment 4 Marc-Andre Lureau 2014-11-02 23:40:48 UTC
please provide updated patch if still required
Comment 5 Fabiano Fidêncio 2015-02-24 14:27:27 UTC
(In reply to Marc-Andre Lureau from comment #4)
> please provide updated patch if still required

Patch sent to ML: http://lists.freedesktop.org/archives/spice-devel/2015-February/019024.html


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.