Skip to content

Commit 4311196

Browse files
committed
Solaris requires a buffer for realpath
1 parent 3ede569 commit 4311196

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/zone.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,14 @@ nonnull_all
174174
static int32_t resolve_path(
175175
const char *includer, const char *include, char **path)
176176
{
177+
char *resolved;
178+
char buffer[PATH_MAX + 1];
179+
177180
if (*includer && *include != '/') {
178181
assert(*includer == '/');
179182
const char *separator = strrchr(includer, '/');
180183
if (separator - include > INT_MAX)
181184
return ZONE_OUT_OF_MEMORY;
182-
char buffer[16];
183185
int offset = (int)(separator - includer);
184186
int length = snprintf(
185187
buffer, sizeof(buffer), "%.*s/%s", offset, includer, include);
@@ -190,15 +192,21 @@ static int32_t resolve_path(
190192
return ZONE_OUT_OF_MEMORY;
191193
(void)snprintf(
192194
absolute, (size_t)length + 1, "%.*s/%s", offset, includer, include);
193-
*path = realpath(absolute, NULL);
195+
resolved = realpath(absolute, buffer);
194196
free(absolute);
195197
} else {
196-
*path = realpath(include, NULL);
198+
resolved = realpath(include, buffer);
197199
}
198200

199-
if (*path)
200-
return 0;
201-
return (errno == ENOMEM) ? ZONE_OUT_OF_MEMORY : ZONE_NOT_A_FILE;
201+
if (!resolved)
202+
return (errno == ENOMEM) ? ZONE_OUT_OF_MEMORY : ZONE_NOT_A_FILE;
203+
assert(resolved == buffer);
204+
size_t length = strlen(buffer);
205+
if (!(resolved = malloc(length + 1)))
206+
return ZONE_OUT_OF_MEMORY;
207+
memcpy(resolved, buffer, length + 1);
208+
*path = resolved;
209+
return 0;
202210
}
203211
#endif
204212

@@ -276,6 +284,7 @@ static int32_t open_file(
276284

277285
initialize_file(parser, file);
278286

287+
file->path = NULL;
279288
if (!(file->name = malloc(length + 1)))
280289
return ZONE_OUT_OF_MEMORY;
281290
memcpy(file->name, include, length);

0 commit comments

Comments
 (0)