[FIX] configure.c: Do not assume git

If parsee were downloaded from sources other than git-clone(1) (e.g.: a
tarball), perror(3) fails and/or git(1) is not available on the system,
"git remote get-url origin" would have unexpected results or even return
a NULL pointer, which would cause undefined behaviour on
strchr(repo, ...);

In such conditions, a placeholder string, namely "N/A", is strdup(3)ed
to `repo`.
This commit is contained in:
Xavier Del Campo Romero 2024-10-17 07:28:07 +02:00
commit 2074d8e768
No known key found for this signature in database
GPG key ID: 84FF3612A9BF43F2

View file

@ -186,18 +186,34 @@ cmd_stdout(char *cmd)
FILE *f;
char *line = NULL;
size_t size;
int result;
if (!cmd)
{
return NULL;
goto failure;
}
if (!(f = popen(cmd, "r")))
{
return NULL;
goto failure;
}
getline(&line, &size, f);
pclose(f);
result = pclose(f);
if (result < 0)
{
perror("pclose(3)");
goto failure;
}
else if (result)
{
fprintf(stderr, "command exited with status %d: %s\n", result, cmd);
goto failure;
}
return line;
failure:
free(line);
return NULL;
}
static int
exec_code(char *program, char *argv[])
@ -426,10 +442,13 @@ main_build(int argc, char *argv[])
int opt;
str_array_t *sources, *images, *utils, *aya;
if (strchr(repo, '\n'))
if (repo)
{
*(strchr(repo, '\n')) = '\0';
char *lf = strchr(repo, '\n');
*lf = '\0';
}
else
repo = strdup("N/A");
while ((opt = getopt(argc, argv, "sl")) != -1)
{