Issue 657: Allow up to 8k for the test root directory name

This commit is contained in:
Tim Kientzle committed 2016-06-02 20:17:13 -07:00
1 parent ed497f0e18
commit 83c3e2e675
4 files changed
+196 -104

No files matched your search

+49 -26
View File
@@ -2534,18 +2534,36 @@ usage(const char *program)
static char *
get_refdir(const char *d)
{
char tried[512] = { '\0' };
char buff[128];
char *pwd, *p;
size_t tried_size, buff_size;
char *buff, *tried, *pwd = NULL, *p = NULL;
#ifdef PATH_MAX
buff_size = PATH_MAX;
#else
buff_size = 8192;
#endif
buff = calloc(buff_size, 1);
if (buff == NULL) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
/* Allocate a buffer to hold the various directories we checked. */
tried_size = buff_size * 2;
tried = calloc(tried_size, 1);
if (tried == NULL) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
/* If a dir was specified, try that */
if (d != NULL) {
pwd = NULL;
snprintf(buff, sizeof(buff), "%s", d);
snprintf(buff, buff_size, "%s", d);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
goto failure;
}
@@ -2559,48 +2577,48 @@ get_refdir(const char *d)
pwd[strlen(pwd) - 1] = '\0';
/* Look for a known file. */
snprintf(buff, sizeof(buff), "%s", pwd);
snprintf(buff, buff_size, "%s", pwd);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd);
snprintf(buff, buff_size, "%s/test", pwd);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#if defined(LIBRARY)
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY);
snprintf(buff, buff_size, "%s/%s/test", pwd, LIBRARY);
#else
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM);
snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM);
#endif
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#if defined(PROGRAM_ALIAS)
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM_ALIAS);
snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM_ALIAS);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#endif
if (memcmp(pwd, "/usr/obj", 8) == 0) {
snprintf(buff, sizeof(buff), "%s", pwd + 8);
snprintf(buff, buff_size, "%s", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
snprintf(buff, buff_size, "%s/test", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
}
failure:
@@ -2615,7 +2633,12 @@ failure:
success:
free(p);
free(pwd);
return strdup(buff);
free(tried);
/* Copy result into a fresh buffer to reduce memory usage. */
p = strdup(buff);
free(buff);
return p;
}
int
+49 -26
View File
@@ -2535,18 +2535,36 @@ usage(const char *program)
static char *
get_refdir(const char *d)
{
char tried[512] = { '\0' };
char buff[128];
char *pwd, *p;
size_t tried_size, buff_size;
char *buff, *tried, *pwd = NULL, *p = NULL;
#ifdef PATH_MAX
buff_size = PATH_MAX;
#else
buff_size = 8192;
#endif
buff = calloc(buff_size, 1);
if (buff == NULL) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
/* Allocate a buffer to hold the various directories we checked. */
tried_size = buff_size * 2;
tried = calloc(tried_size, 1);
if (tried == NULL) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
/* If a dir was specified, try that */
if (d != NULL) {
pwd = NULL;
snprintf(buff, sizeof(buff), "%s", d);
snprintf(buff, buff_size, "%s", d);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
goto failure;
}
@@ -2560,48 +2578,48 @@ get_refdir(const char *d)
pwd[strlen(pwd) - 1] = '\0';
/* Look for a known file. */
snprintf(buff, sizeof(buff), "%s", pwd);
snprintf(buff, buff_size, "%s", pwd);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd);
snprintf(buff, buff_size, "%s/test", pwd);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#if defined(LIBRARY)
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY);
snprintf(buff, buff_size, "%s/%s/test", pwd, LIBRARY);
#else
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM);
snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM);
#endif
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#if defined(PROGRAM_ALIAS)
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM_ALIAS);
snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM_ALIAS);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#endif
if (memcmp(pwd, "/usr/obj", 8) == 0) {
snprintf(buff, sizeof(buff), "%s", pwd + 8);
snprintf(buff, buff_size, "%s", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
snprintf(buff, buff_size, "%s/test", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
}
failure:
@@ -2616,7 +2634,12 @@ failure:
success:
free(p);
free(pwd);
return strdup(buff);
free(tried);
/* Copy result into a fresh buffer to reduce memory usage. */
p = strdup(buff);
free(buff);
return p;
}
int
+49 -26
View File
@@ -2533,18 +2533,36 @@ usage(const char *program)
static char *
get_refdir(const char *d)
{
char tried[512] = { '\0' };
char buff[128];
char *pwd, *p;
size_t tried_size, buff_size;
char *buff, *tried, *pwd = NULL, *p = NULL;
#ifdef PATH_MAX
buff_size = PATH_MAX;
#else
buff_size = 8192;
#endif
buff = calloc(buff_size, 1);
if (buff == NULL) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
/* Allocate a buffer to hold the various directories we checked. */
tried_size = buff_size * 2;
tried = calloc(tried_size, 1);
if (tried == NULL) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
/* If a dir was specified, try that */
if (d != NULL) {
pwd = NULL;
snprintf(buff, sizeof(buff), "%s", d);
snprintf(buff, buff_size, "%s", d);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
goto failure;
}
@@ -2558,48 +2576,48 @@ get_refdir(const char *d)
pwd[strlen(pwd) - 1] = '\0';
/* Look for a known file. */
snprintf(buff, sizeof(buff), "%s", pwd);
snprintf(buff, buff_size, "%s", pwd);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd);
snprintf(buff, buff_size, "%s/test", pwd);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#if defined(LIBRARY)
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY);
snprintf(buff, buff_size, "%s/%s/test", pwd, LIBRARY);
#else
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM);
snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM);
#endif
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#if defined(PROGRAM_ALIAS)
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM_ALIAS);
snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM_ALIAS);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#endif
if (memcmp(pwd, "/usr/obj", 8) == 0) {
snprintf(buff, sizeof(buff), "%s", pwd + 8);
snprintf(buff, buff_size, "%s", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
snprintf(buff, buff_size, "%s/test", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
}
failure:
@@ -2614,7 +2632,12 @@ failure:
success:
free(p);
free(pwd);
return strdup(buff);
free(tried);
/* Copy result into a fresh buffer to reduce memory usage. */
p = strdup(buff);
free(buff);
return p;
}
int
+49 -26
View File
@@ -2535,18 +2535,36 @@ usage(const char *program)
static char *
get_refdir(const char *d)
{
char tried[512] = { '\0' };
char buff[128];
char *pwd, *p;
size_t tried_size, buff_size;
char *buff, *tried, *pwd = NULL, *p = NULL;
#ifdef PATH_MAX
buff_size = PATH_MAX;
#else
buff_size = 8192;
#endif
buff = calloc(buff_size, 1);
if (buff == NULL) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
/* Allocate a buffer to hold the various directories we checked. */
tried_size = buff_size * 2;
tried = calloc(tried_size, 1);
if (tried == NULL) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
/* If a dir was specified, try that */
if (d != NULL) {
pwd = NULL;
snprintf(buff, sizeof(buff), "%s", d);
snprintf(buff, buff_size, "%s", d);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
goto failure;
}
@@ -2560,48 +2578,48 @@ get_refdir(const char *d)
pwd[strlen(pwd) - 1] = '\0';
/* Look for a known file. */
snprintf(buff, sizeof(buff), "%s", pwd);
snprintf(buff, buff_size, "%s", pwd);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd);
snprintf(buff, buff_size, "%s/test", pwd);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#if defined(LIBRARY)
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY);
snprintf(buff, buff_size, "%s/%s/test", pwd, LIBRARY);
#else
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM);
snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM);
#endif
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#if defined(PROGRAM_ALIAS)
snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM_ALIAS);
snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM_ALIAS);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
#endif
if (memcmp(pwd, "/usr/obj", 8) == 0) {
snprintf(buff, sizeof(buff), "%s", pwd + 8);
snprintf(buff, buff_size, "%s", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
snprintf(buff, buff_size, "%s/test", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
strncat(tried, buff, tried_size - strlen(tried) - 1);
strncat(tried, "\n", tried_size - strlen(tried) - 1);
}
failure:
@@ -2616,7 +2634,12 @@ failure:
success:
free(p);
free(pwd);
return strdup(buff);
free(tried);
/* Copy result into a fresh buffer to reduce memory usage. */
p = strdup(buff);
free(buff);
return p;
}
int