From: Sebastien GODARD Date: Sat, 6 Feb 2021 17:09:46 +0000 (+0100) Subject: sar/sadf: Test values returned by functions X-Git-Tag: v12.5.3~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=44ce5078c7c8b1403a4ee5a1bd8293ff1034607e;p=sysstat sar/sadf: Test values returned by functions Signed-off-by: Sebastien GODARD --- diff --git a/sa.h b/sa.h index 6107971..9029a93 100644 --- a/sa.h +++ b/sa.h @@ -1486,7 +1486,7 @@ void handle_invalid_sa_file (int, struct file_magic *, char *, int); void print_collect_error (void); -int set_default_file +void set_default_file (char *, int, int); int skip_extra_struct (int, int, int); diff --git a/sa_common.c b/sa_common.c index 8d1eb17..27aa4cb 100644 --- a/sa_common.c +++ b/sa_common.c @@ -198,13 +198,9 @@ void guess_sa_name(char *sa_dir, struct tm *rectime, int *sa_name) * * OUT: * @datafile Name of daily data file. - * - * RETURNS: - * 1 if an output error has been encountered or if datafile name has been - * truncated, or 0 otherwise. *************************************************************************** */ -int set_default_file(char *datafile, int d_off, int sa_name) +void set_default_file(char *datafile, int d_off, int sa_name) { char sa_dir[MAX_FILE_LEN]; struct tm rectime = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL}; @@ -243,13 +239,17 @@ int set_default_file(char *datafile, int d_off, int sa_name) rectime.tm_mday); } datafile[MAX_FILE_LEN - 1] = '\0'; + + if ((err < 0) || (err >= MAX_FILE_LEN)) { + fprintf(stderr, "%s: %s\n", __FUNCTION__, datafile); + exit(1); + } + default_file_used = TRUE; #ifdef DEBUG fprintf(stderr, "%s: Datafile: %s\n", __FUNCTION__, datafile); #endif - - return ((err < 0) || (err >= MAX_FILE_LEN)); } /* diff --git a/sadf.c b/sadf.c index 4982197..c648692 100644 --- a/sadf.c +++ b/sadf.c @@ -230,7 +230,7 @@ void check_format_options(void) * * RETURNS: * 1 if EOF has been reached, - * 2 if an unexpected EOF has been reached, + * 2 if an unexpected EOF has been reached, or an error occurred. * 0 otherwise. *************************************************************************** */ @@ -265,8 +265,9 @@ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int return 2; if (action & SET_TIMESTAMPS) { - sa_get_record_timestamp_struct(flags, &record_hdr[curr], - rectime); + if (sa_get_record_timestamp_struct(flags, &record_hdr[curr], + rectime)) + return 2; } } else { @@ -293,7 +294,8 @@ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int return 2; } if (action & SET_TIMESTAMPS) { - sa_get_record_timestamp_struct(flags, &record_hdr[curr], rectime); + if (sa_get_record_timestamp_struct(flags, &record_hdr[curr], rectime)) + return 2; } } else { @@ -312,7 +314,8 @@ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int if (read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr, file_actlst, endian_mismatch, arch_64, file, file_magic, oneof) > 0) return 2; - sa_get_record_timestamp_struct(flags, &record_hdr[curr], rectime); + if (sa_get_record_timestamp_struct(flags, &record_hdr[curr], rectime)) + return 2; } return 0; diff --git a/sar.c b/sar.c index 490016b..519ad65 100644 --- a/sar.c +++ b/sar.c @@ -800,8 +800,10 @@ void handle_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf if (rtype != R_COMMENT) { /* Read the extra fields since it's not a special record */ - read_file_stat_bunch(act, *curr, ifd, file_hdr.sa_act_nr, file_actlst, - endian_mismatch, arch_64, file, file_magic, UEOF_STOP); + if (read_file_stat_bunch(act, *curr, ifd, file_hdr.sa_act_nr, file_actlst, + endian_mismatch, arch_64, file, file_magic, UEOF_STOP)) + /* Error or unexpected EOF */ + break; } else { /* Display comment */ @@ -1045,9 +1047,12 @@ void read_stats_from_file(char from_file[]) * OK: Previous record was not a special one. * So read now the extra fields. */ - read_file_stat_bunch(act, 0, ifd, file_hdr.sa_act_nr, - file_actlst, endian_mismatch, arch_64, - from_file, &file_magic, UEOF_STOP); + if (read_file_stat_bunch(act, 0, ifd, file_hdr.sa_act_nr, + file_actlst, endian_mismatch, arch_64, + from_file, &file_magic, UEOF_STOP)) + /* Possible unexpected EOF */ + return; + if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME, &record_hdr[0], &rectime)) /* @@ -1133,9 +1138,11 @@ void read_stats_from_file(char from_file[]) break; if (rtype != R_COMMENT) { - read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr, - file_actlst, endian_mismatch, arch_64, - from_file, &file_magic, UEOF_STOP); + if (read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr, + file_actlst, endian_mismatch, arch_64, + from_file, &file_magic, UEOF_STOP)) + /* Possible unexpected EOF */ + break; } else { /* This was a COMMENT record: Print it */ diff --git a/svg_stats.c b/svg_stats.c index b0ab564..5427458 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -670,7 +670,12 @@ void display_vgrid(long int xpos, double xfactor, int v_gridnr, struct svg_parm for (j = 0; (j <= (2 * v_gridnr)) && (stamp.ust_time <= svg_p->ust_time_end); j++) { /* Display vertical lines */ - sa_get_record_timestamp_struct(flags, &stamp, &rectime); + if (sa_get_record_timestamp_struct(flags, &stamp, &rectime)) { +#ifdef DEBUG + fprintf(stderr, "%s: ust_time: %llu\n", __FUNCTION__, stamp.ust_time); +#endif + exit(1); + } set_record_timestamp_string(flags, &stamp, NULL, cur_time, TIMESTAMP_LEN, &rectime); printf("\n",