Skip to content

Commit

Permalink
fix: Give in to clang disagnostics
Browse files Browse the repository at this point in the history
memcpy() -> memcpy_s()
  • Loading branch information
abelcheung committed Dec 11, 2023
1 parent ac579fc commit d7902ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/rifiuti-vista.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ _validate_index_file (const char *filename,
return FALSE;
}

copy_field (ver, VERSION_OFFSET, FILESIZE_OFFSET);
copy_field (*ver, VERSION_OFFSET, FILESIZE_OFFSET);
*ver = GUINT64_FROM_LE (*ver);
g_debug ("version = %" PRIu64, *ver);

Expand All @@ -88,7 +88,7 @@ _validate_index_file (const char *filename,

// Version 2 adds a uint32 file name strlen before file name.
// This presumably breaks the 260 char barrier in version 1.
copy_field (&pathlen, VERSION1_FILENAME_OFFSET, VERSION2_FILENAME_OFFSET);
copy_field (pathlen, VERSION1_FILENAME_OFFSET, VERSION2_FILENAME_OFFSET);
pathlen = GUINT32_FROM_LE (pathlen);

/* Header length + strlen in UTF-16 encoding */
Expand Down Expand Up @@ -140,7 +140,8 @@ _populate_record_data (void *buf,
* bug inside Windows. This is observed during deletion of dd.exe from Forensic
* Acquisition Utilities (by George M. Garner Jr) in certain localized Vista.
*/
memcpy (&record->filesize, buf + FILESIZE_OFFSET,
memcpy_s (&record->filesize, sizeof(record->filesize),
buf + FILESIZE_OFFSET,
FILETIME_OFFSET - FILESIZE_OFFSET - (int) erraneous);
if (erraneous)
{
Expand All @@ -156,7 +157,8 @@ _populate_record_data (void *buf,
}

/* File deletion time */
memcpy (&record->winfiletime, buf + FILETIME_OFFSET - (int) erraneous,
memcpy_s (&record->winfiletime, sizeof(record->winfiletime),
buf + FILETIME_OFFSET - (int) erraneous,
VERSION1_FILENAME_OFFSET - FILETIME_OFFSET);
record->winfiletime = GINT64_FROM_LE (record->winfiletime);
record->deltime = win_filetime_to_gdatetime (record->winfiletime);
Expand Down
18 changes: 10 additions & 8 deletions src/rifiuti.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ _validate_index_file (const char *filename,
goto validation_broken;
}

copy_field (&ver, VERSION_OFFSET, KEPT_ENTRY_OFFSET);
copy_field (ver, VERSION_OFFSET, KEPT_ENTRY_OFFSET);
ver = GUINT32_FROM_LE (ver);

// total_entry only meaningful for 95 and NT4, on other versions
// it's junk memory data, don't bother copying
if ( ( ver == VERSION_NT4 ) || ( ver == VERSION_WIN95 ) ) {
copy_field (&meta->total_entry, TOTAL_ENTRY_OFFSET, RECORD_SIZE_OFFSET);
copy_field (meta->total_entry, TOTAL_ENTRY_OFFSET, RECORD_SIZE_OFFSET);
meta->total_entry = GUINT32_FROM_LE (meta->total_entry);
}

copy_field (&meta->recordsize, RECORD_SIZE_OFFSET, FILESIZE_SUM_OFFSET);
copy_field (meta->recordsize, RECORD_SIZE_OFFSET, FILESIZE_SUM_OFFSET);
meta->recordsize = GUINT32_FROM_LE (meta->recordsize);

g_free (buf);
Expand Down Expand Up @@ -148,15 +148,17 @@ _populate_record_data (void *buf,
record = g_malloc0 (sizeof (rbin_struct));

legacy_fname = g_malloc0 (RECORD_INDEX_OFFSET - LEGACY_FILENAME_OFFSET);
copy_field (legacy_fname, LEGACY_FILENAME_OFFSET, RECORD_INDEX_OFFSET);
memcpy_s (legacy_fname, RECORD_INDEX_OFFSET - LEGACY_FILENAME_OFFSET,
buf + LEGACY_FILENAME_OFFSET,
RECORD_INDEX_OFFSET - LEGACY_FILENAME_OFFSET);

/* Index number associated with the record */
copy_field (&record->index_n, RECORD_INDEX_OFFSET, DRIVE_LETTER_OFFSET);
copy_field (record->index_n, RECORD_INDEX_OFFSET, DRIVE_LETTER_OFFSET);
record->index_n = GUINT32_FROM_LE (record->index_n);
g_debug ("index=%u", record->index_n);

/* Number representing drive letter, 'A:' = 0, etc */
copy_field (&drivenum, DRIVE_LETTER_OFFSET, FILETIME_OFFSET);
copy_field (drivenum, DRIVE_LETTER_OFFSET, FILETIME_OFFSET);
drivenum = GUINT32_FROM_LE (drivenum);
g_debug ("drive=%u", drivenum);
if (drivenum >= sizeof (driveletters) - 1) {
Expand All @@ -177,13 +179,13 @@ _populate_record_data (void *buf,
}

/* File deletion time */
copy_field (&record->winfiletime, FILETIME_OFFSET, FILESIZE_OFFSET);
copy_field (record->winfiletime, FILETIME_OFFSET, FILESIZE_OFFSET);
record->winfiletime = GINT64_FROM_LE (record->winfiletime);
record->deltime = win_filetime_to_gdatetime (record->winfiletime);

/* File size or occupied cluster size */
/* BEWARE! This is 32bit data casted to 64bit struct member */
copy_field (&record->filesize, FILESIZE_OFFSET, UNICODE_FILENAME_OFFSET);
copy_field (record->filesize, FILESIZE_OFFSET, UNICODE_FILENAME_OFFSET);
record->filesize = GUINT64_FROM_LE (record->filesize);
g_debug ("filesize=%" PRIu64, record->filesize);

Expand Down
4 changes: 2 additions & 2 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ typedef struct _rbin_struct

} rbin_struct;

/* convenience macro */
/* convenience macro that copies fixed size field */
#define copy_field(field, off1, off2) \
memcpy((field), buf + (off1), (off2) - (off1))
memcpy_s(&(field), sizeof(field), buf + (off1), (off2) - (off1))

/*! Every Windows use this GUID in recycle bin desktop.ini */
#define RECYCLE_BIN_CLSID "645FF040-5081-101B-9F08-00AA002F954E"
Expand Down

0 comments on commit d7902ef

Please sign in to comment.