1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

cmirrord: avoid resync buffer overflow in LOG_SPRINT

Use snprintf() instead of sprintf() to exclude the possibility of
overflowing the resync history buffers.
This commit is contained in:
Ferenc Wágner 2015-07-08 14:41:27 +02:00 committed by Heinz Mauelshagen
parent 3c396cf1e1
commit 5476ee8655

View File

@ -32,12 +32,13 @@
#define LOG_OFFSET 2 #define LOG_OFFSET 2
#define RESYNC_HISTORY 50 #define RESYNC_HISTORY 50
#define RESYNC_BUFLEN 128
//static char resync_history[RESYNC_HISTORY][128]; //static char resync_history[RESYNC_HISTORY][128];
//static int idx = 0; //static int idx = 0;
#define LOG_SPRINT(_lc, f, arg...) do { \ #define LOG_SPRINT(_lc, f, arg...) do { \
lc->idx++; \ lc->idx++; \
lc->idx = lc->idx % RESYNC_HISTORY; \ lc->idx = lc->idx % RESYNC_HISTORY; \
sprintf(lc->resync_history[lc->idx], f, ## arg); \ snprintf(lc->resync_history[lc->idx], RESYNC_BUFLEN, f, ## arg); \
} while (0) } while (0)
struct log_header { struct log_header {
@ -88,7 +89,7 @@ struct log_c {
size_t disk_size; /* size of disk_buffer in bytes */ size_t disk_size; /* size of disk_buffer in bytes */
void *disk_buffer; /* aligned memory for O_DIRECT */ void *disk_buffer; /* aligned memory for O_DIRECT */
int idx; int idx;
char resync_history[RESYNC_HISTORY][128]; char resync_history[RESYNC_HISTORY][RESYNC_BUFLEN];
}; };
struct mark_entry { struct mark_entry {