#define FILE_ACTIVITY_UL_NR 0 /* Nr of unsigned long in file_activity structure */
#define FILE_ACTIVITY_U_NR 9 /* Nr of [unsigned] int in file_activity structure */
+#define MAX_ITEM_STRUCT_SIZE 1024 /* Used for sanity check */
+
/*
* Description of an extra structure.
* The composition of this structure should not change in time.
*/
unsigned char record_type;
/*
- * Timestamp: Hour (0-23), minute (0-59) and second (0-59).
+ * Timestamp: Hour (0-23), minute (0-59) and second (0-60).
* Used to determine TRUE time.
* Hour value depends in fact on timezone (TZ variable) value.
*/
record_hdr->hour, record_hdr->minute, record_hdr->second);
}
+ /* Sanity checks */
+ if ((record_hdr->record_type <= 0) || (record_hdr->record_type > R_EXTRA_MAX) ||
+ (record_hdr->hour > 23) || (record_hdr->minute > 59) || (record_hdr->second > 60)) {
+#ifdef DEBUG
+ fprintf(stderr, "%s: record_type=%d HH:MM:SS=%02d:%02d:%02d\n",
+ __FUNCTION__, record_hdr->record_type,
+ record_hdr->hour, record_hdr->minute, record_hdr->second);
+#endif
+ return 2;
+ }
+
/*
* Skip unknown extra structures if present.
* This will be done later for R_COMMENT and R_RESTART records, as extra structures
/*
* Every activity, known or unknown, should have
- * at least one item and sub-item, and a positive size value.
+ * at least one item and sub-item, and a size value in
+ * a defined range.
* Also check that the number of items and sub-items
* doesn't exceed a max value. This is necessary
* because we will use @nr and @nr2 to
*/
if ((fal->nr < 1) || (fal->nr2 < 1) ||
(fal->nr > NR_MAX) || (fal->nr2 > NR2_MAX) ||
- (fal->size <= 0)) {
+ (fal->size <= 0) || (fal->size > MAX_ITEM_STRUCT_SIZE)) {
#ifdef DEBUG
- fprintf(stderr, "%s: id=%d nr=%d nr2=%d\n",
- __FUNCTION__, fal->id, fal->nr, fal->nr2);
+ fprintf(stderr, "%s: id=%d nr=%d nr2=%d size=%d\n",
+ __FUNCTION__, fal->id, fal->nr, fal->nr2, fal->size);
#endif
goto format_error;
}