[ltt-dev] [UST PATCH 1/2] fix sscanf format string v2
Douglas Santos
douglas.santos at polymtl.ca
Mon Sep 13 15:28:06 EDT 2010
Signed-off-by: Douglas Santos <douglas.santos at polymtl.ca>
---
libust/tracectl.c | 22 +++++++++++++++-------
1 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/libust/tracectl.c b/libust/tracectl.c
index dd61ebe..b0a2daa 100644
--- a/libust/tracectl.c
+++ b/libust/tracectl.c
@@ -529,7 +529,7 @@ static unsigned int pow2_higher_or_eq(unsigned int v)
static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *src)
{
char *channel_slash_size;
- char ch_name[256]="";
+ char *ch_name;
unsigned int size, power;
int retval = 0;
struct ust_trace *trace;
@@ -540,7 +540,7 @@ static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *sr
DBG("set_subbuf_size");
channel_slash_size = nth_token(recvbuf, 1);
- sscanf(channel_slash_size, "%255[^/]/%u", ch_name, &size);
+ sscanf(channel_slash_size, "%a[^/]/%u", &ch_name, &size);
if(ch_name == NULL) {
ERR("cannot parse channel");
@@ -578,6 +578,7 @@ static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *sr
}
end:
+ free(ch_name);
ltt_unlock_traces();
return retval;
}
@@ -585,7 +586,7 @@ static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *sr
static int do_cmd_set_subbuf_num(const char *recvbuf, struct ustcomm_source *src)
{
char *channel_slash_num;
- char ch_name[256]="";
+ char *ch_name;
unsigned int num;
int retval = 0;
struct ust_trace *trace;
@@ -596,7 +597,7 @@ static int do_cmd_set_subbuf_num(const char *recvbuf, struct ustcomm_source *src
DBG("set_subbuf_num");
channel_slash_num = nth_token(recvbuf, 1);
- sscanf(channel_slash_num, "%255[^/]/%u", ch_name, &num);
+ sscanf(channel_slash_num, "%a[^/]/%u", &ch_name, &num);
if(ch_name == NULL) {
ERR("cannot parse channel");
@@ -634,6 +635,7 @@ static int do_cmd_set_subbuf_num(const char *recvbuf, struct ustcomm_source *src
}
end:
+ free(ch_name);
ltt_unlock_traces();
return retval;
}
@@ -1042,10 +1044,10 @@ int process_client_cmd(char *recvbuf, struct ustcomm_source *src)
}
else if(nth_token_is(recvbuf, "enable_marker", 0) == 1) {
char *channel_slash_name = nth_token(recvbuf, 1);
- char channel_name[256]="";
- char marker_name[256]="";
+ char *channel_name;
+ char *marker_name;
- result = sscanf(channel_slash_name, "%255[^/]/%255s", channel_name, marker_name);
+ result = sscanf(channel_slash_name, "%a[^/]/%as", &channel_name, &marker_name);
if(channel_name == NULL || marker_name == NULL) {
WARN("invalid marker name");
@@ -1056,6 +1058,9 @@ int process_client_cmd(char *recvbuf, struct ustcomm_source *src)
if(result < 0) {
WARN("could not enable marker; channel=%s, name=%s", channel_name, marker_name);
}
+
+ free(channel_name);
+ free(marker_name);
}
else if(nth_token_is(recvbuf, "disable_marker", 0) == 1) {
char *channel_slash_name = nth_token(recvbuf, 1);
@@ -1073,6 +1078,9 @@ int process_client_cmd(char *recvbuf, struct ustcomm_source *src)
if(result < 0) {
WARN("could not disable marker; channel=%s, name=%s", channel_name, marker_name);
}
+
+ free(marker_name);
+ free(channel_name);
}
else if(nth_token_is(recvbuf, "get_pidunique", 0) == 1) {
char *reply;
--
1.7.0.4
More information about the lttng-dev
mailing list