* [PATCH] Missing error checking in cmirrord
@ 2010-06-18 21:10 Jonathan Brassow
2010-06-19 0:55 ` Alasdair G Kergon
2010-06-21 20:11 ` Milan Broz
0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Brassow @ 2010-06-18 21:10 UTC (permalink / raw)
To: lvm-devel
There are missing error checks... it's possible for
sprintf to fail.
brassow
Index: LVM2/daemons/cmirrord/functions.c
===================================================================
--- LVM2.orig/daemons/cmirrord/functions.c
+++ LVM2/daemons/cmirrord/functions.c
@@ -1371,15 +1371,21 @@ static int clog_get_sync_count(struct dm
static int core_status_info(struct log_c *lc __attribute((unused)), struct dm_ulog_request *rq)
{
+ int r;
char *data = (char *)rq->data;
- rq->data_size = sprintf(data, "1 clustered-core");
+ r = sprintf(data, "1 clustered-core");
+ if (r < 0)
+ return r;
+
+ rq->data_size = r;
return 0;
}
static int disk_status_info(struct log_c *lc, struct dm_ulog_request *rq)
{
+ int r;
char *data = (char *)rq->data;
struct stat statbuf;
@@ -1388,9 +1394,13 @@ static int disk_status_info(struct log_c
return -errno;
}
- rq->data_size = sprintf(data, "3 clustered-disk %d:%d %c",
- major(statbuf.st_rdev), minor(statbuf.st_rdev),
- (lc->log_dev_failed) ? 'D' : 'A');
+ r = sprintf(data, "3 clustered-disk %d:%d %c",
+ major(statbuf.st_rdev), minor(statbuf.st_rdev),
+ (lc->log_dev_failed) ? 'D' : 'A');
+ if (r < 0)
+ return r;
+
+ rq->data_size = r;
return 0;
}
@@ -1421,18 +1431,24 @@ static int clog_status_info(struct dm_ul
static int core_status_table(struct log_c *lc, struct dm_ulog_request *rq)
{
+ int r;
char *data = (char *)rq->data;
- rq->data_size = sprintf(data, "clustered-core %u %s%s ",
- lc->region_size,
- (lc->sync == DEFAULTSYNC) ? "" :
- (lc->sync == NOSYNC) ? "nosync " : "sync ",
- (lc->block_on_error) ? "block_on_error" : "");
+ r = sprintf(data, "clustered-core %u %s%s ",
+ lc->region_size,
+ (lc->sync == DEFAULTSYNC) ? "" :
+ (lc->sync == NOSYNC) ? "nosync " : "sync ",
+ (lc->block_on_error) ? "block_on_error" : "");
+ if (r < 0)
+ return r;
+
+ rq->data_size = r;
return 0;
}
static int disk_status_table(struct log_c *lc, struct dm_ulog_request *rq)
{
+ int r;
char *data = (char *)rq->data;
struct stat statbuf;
@@ -1441,12 +1457,16 @@ static int disk_status_table(struct log_
return -errno;
}
- rq->data_size = sprintf(data, "clustered-disk %d:%d %u %s%s ",
- major(statbuf.st_rdev), minor(statbuf.st_rdev),
- lc->region_size,
- (lc->sync == DEFAULTSYNC) ? "" :
- (lc->sync == NOSYNC) ? "nosync " : "sync ",
- (lc->block_on_error) ? "block_on_error" : "");
+ r = sprintf(data, "clustered-disk %d:%d %u %s%s ",
+ major(statbuf.st_rdev), minor(statbuf.st_rdev),
+ lc->region_size,
+ (lc->sync == DEFAULTSYNC) ? "" :
+ (lc->sync == NOSYNC) ? "nosync " : "sync ",
+ (lc->block_on_error) ? "block_on_error" : "");
+ if (r < 0)
+ return r;
+
+ rq->data_size = r;
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Missing error checking in cmirrord
2010-06-18 21:10 [PATCH] Missing error checking in cmirrord Jonathan Brassow
@ 2010-06-19 0:55 ` Alasdair G Kergon
2010-06-21 20:11 ` Milan Broz
1 sibling, 0 replies; 3+ messages in thread
From: Alasdair G Kergon @ 2010-06-19 0:55 UTC (permalink / raw)
To: lvm-devel
On Fri, Jun 18, 2010 at 04:10:20PM -0500, Jon Brassow wrote:
> There are missing error checks... it's possible for
> sprintf to fail.
And an inline comment to explain how data has an adequate minimum size
perhaps?
Alasdair
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Missing error checking in cmirrord
2010-06-18 21:10 [PATCH] Missing error checking in cmirrord Jonathan Brassow
2010-06-19 0:55 ` Alasdair G Kergon
@ 2010-06-21 20:11 ` Milan Broz
1 sibling, 0 replies; 3+ messages in thread
From: Milan Broz @ 2010-06-21 20:11 UTC (permalink / raw)
To: lvm-devel
On 06/18/2010 11:10 PM, Jonathan Brassow wrote:
> There are missing error checks... it's possible for
> sprintf to fail.
>
> brassow
>
> Index: LVM2/daemons/cmirrord/functions.c
> ===================================================================
> --- LVM2.orig/daemons/cmirrord/functions.c
> +++ LVM2/daemons/cmirrord/functions.c
> @@ -1371,15 +1371,21 @@ static int clog_get_sync_count(struct dm
>
> static int core_status_info(struct log_c *lc __attribute((unused)), struct dm_ulog_request *rq)
> {
> + int r;
> char *data = (char *)rq->data;
>
> - rq->data_size = sprintf(data, "1 clustered-core");
rq->data_size = 0;
> + r = sprintf(data, "1 clustered-core");
> + if (r < 0)
> + return r;
> +
> + rq->data_size = r;
rq->data_size = r + 1;
sprintf does not count trailing \0 ... (and this is probably part of
the mysterious fails of cmirrord).
Milan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-06-21 20:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-18 21:10 [PATCH] Missing error checking in cmirrord Jonathan Brassow
2010-06-19 0:55 ` Alasdair G Kergon
2010-06-21 20:11 ` Milan Broz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.