Skip to content

Commit dae4e14

Browse files
committed
Replace BUFSIZ with STASIS_BUFSIZ
1 parent 8542661 commit dae4e14

7 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/lib/core/conda.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ int pkg_index_provides(int mode, const char *index, const char *spec, const char
230230
remove(logfile);
231231
return -1;
232232
} else {
233-
char line[BUFSIZ] = {0};
233+
char line[STASIS_BUFSIZ] = {0};
234234
fflush(stdout);
235235
fflush(stderr);
236236
while (fgets(line, sizeof(line) - 1, fp) != NULL) {

src/lib/core/ini.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ int ini_getval(struct INIFILE *ini, char *section_name, char *key, int type, int
181181
}
182182
break;
183183
case INIVAL_TYPE_STR_ARRAY:
184+
// TODO: data_copy should be at least equal to the length of the data. The use of STASIS_BUFSIZ below is
185+
// the root cause of crashes when stasis reads long arrays.
184186
strncpy(tbufp, data_copy, sizeof(tbuf) - 1);
185187
tbuf[sizeof(tbuf) - 1] = '\0';
186188
guard_free(data_copy);
@@ -192,10 +194,11 @@ int ini_getval(struct INIFILE *ini, char *section_name, char *key, int type, int
192194
while ((token = strsep(&tbufp, "\n")) != NULL) {
193195
//lstrip(token);
194196
if (!isempty(token)) {
195-
strncat(data_copy, token, BUFSIZ - strlen(data_copy) - 1);
196-
strncat(data_copy, "\n", BUFSIZ - strlen(data_copy) - 1);
197+
strncat(data_copy, token, STASIS_BUFSIZ - strlen(data_copy) - 1);
198+
strncat(data_copy, "\n", STASIS_BUFSIZ - strlen(data_copy) - 1);
197199
}
198200
}
201+
data_copy[STASIS_BUFSIZ - 1] = '\0';
199202
strip(data_copy);
200203
result->as_char_p = strdup(data_copy);
201204
break;

src/lib/core/multiprocessing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ static int show_log_contents(FILE *stream, struct MultiProcessingTask *task) {
270270
if (!fp) {
271271
return -1;
272272
}
273-
char buf[BUFSIZ] = {0};
273+
char buf[STASIS_BUFSIZ] = {0};
274274
while ((fgets(buf, sizeof(buf) - 1, fp)) != NULL) {
275275
fprintf(stream, "%s", buf);
276276
memset(buf, 0, sizeof(buf));

tests/test_download.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void test_download() {
2121

2222
for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) {
2323
const char *filename = "output.txt";
24-
char errmsg[BUFSIZ] = {0};
24+
char errmsg[STASIS_BUFSIZ] = {0};
2525
char *errmsg_p = errmsg;
2626
long http_code = download((char *) tc[i].url, filename, &errmsg_p);
2727
if (tc[i].errmsg) {

tests/test_environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void test_runtime() {
5656
STASIS_ASSERT(strcmp(global_custom_value, custom_value) == 0, "local and global CUSTOM_KEY variable are supposed to be identical");
5757
guard_free(custom_value);
5858

59-
char output_truth[BUFSIZ] = {0};
59+
char output_truth[STASIS_BUFSIZ] = {0};
6060
char *your_path = runtime_get(env, "PATH");
6161
snprintf(output_truth, sizeof(output_truth), "Your PATH is '%s'.", your_path);
6262
guard_free(your_path);

tests/test_relocation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void test_replace_text() {
1313
for (size_t i = 0; i < sizeof(targets) / sizeof(*targets); i += 2) {
1414
const char *target = targets[i];
1515
const char *expected = targets[i + 1];
16-
char input[BUFSIZ] = {0};
16+
char input[STASIS_BUFSIZ] = {0};
1717
strncpy(input, test_string, sizeof(input) - 1);
1818
input[sizeof(input) - 1] = '\0';
1919

@@ -44,7 +44,7 @@ void test_file_replace_text() {
4444
return;
4545
}
4646

47-
char input[BUFSIZ] = {0};
47+
char input[STASIS_BUFSIZ] = {0};
4848
fp = fopen(filename, "r");
4949
if (fp) {
5050
fread(input, sizeof(*input), sizeof(input), fp);

tests/test_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void test_xml_pretty_print_in_place() {
105105
}
106106

107107
fp = fopen(filename, "r");
108-
char buf[BUFSIZ] = {0};
108+
char buf[STASIS_BUFSIZ] = {0};
109109
if (fread(buf, sizeof(*buf), sizeof(buf) - 1, fp) < 1) {
110110
STASIS_ASSERT(false, "failed to consume formatted xml file contents");
111111
}

0 commit comments

Comments
 (0)