This eliminates a warning produced by GCC 8 in that repeated
code pattern (potential truncation of the source string) and
using the lttng_strncpy macro reduces code duplication.
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
} else if (!strcmp((const char *) probe_attribute_node->name,
config_element_symbol_name)) {
xmlChar *content;
} else if (!strcmp((const char *) probe_attribute_node->name,
config_element_symbol_name)) {
xmlChar *content;
/* symbol_name */
content = xmlNodeGetContent(probe_attribute_node);
/* symbol_name */
content = xmlNodeGetContent(probe_attribute_node);
- name_len = strlen((char *) content);
- if (name_len >= LTTNG_SYMBOL_NAME_LEN) {
- WARN("symbol_name too long.");
+ ret = lttng_strncpy(attr->symbol_name,
+ (const char *) content,
+ LTTNG_SYMBOL_NAME_LEN);
+ if (ret == -1) {
+ ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
+ (const char *) content,
+ strlen((const char *) content),
+ LTTNG_SYMBOL_NAME_LEN);
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
free(content);
goto end;
}
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
free(content);
goto end;
}
-
- strncpy(attr->symbol_name, (const char *) content, name_len);
free(content);
}
ret = 0;
free(content);
}
ret = 0;
node = xmlNextElementSibling(node)) {
if (!strcmp((const char *) node->name, config_element_name)) {
xmlChar *content;
node = xmlNextElementSibling(node)) {
if (!strcmp((const char *) node->name, config_element_name)) {
xmlChar *content;
/* name */
content = xmlNodeGetContent(node);
/* name */
content = xmlNodeGetContent(node);
- name_len = strlen((char *) content);
- if (name_len >= LTTNG_SYMBOL_NAME_LEN) {
- WARN("Channel name too long.");
+ ret = lttng_strncpy(event.name,
+ (const char *) content,
+ LTTNG_SYMBOL_NAME_LEN);
+ if (ret == -1) {
+ WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
+ (const char *) content,
+ strlen((const char *) content),
+ LTTNG_SYMBOL_NAME_LEN);
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
free(content);
goto end;
}
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
free(content);
goto end;
}
-
- strncpy(event.name, (const char *) content, name_len);
free(content);
} else if (!strcmp((const char *) node->name,
config_element_enabled)) {
free(content);
} else if (!strcmp((const char *) node->name,
config_element_enabled)) {
- strncpy(event.attr.ftrace.symbol_name, (char *) content,
- sym_len);
+ ret = lttng_strncpy(
+ event.attr.ftrace.symbol_name,
+ (char *) content, sym_len);
+ if (ret == -1) {
+ ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
+ free(content);
+ goto end;
+ }
end:
for (i = 0; i < exclusion_count; i++) {
free(exclusions[i]);
end:
for (i = 0; i < exclusion_count; i++) {
free(exclusions[i]);
if (!strcmp((const char *) attr_node->name, config_element_name)) {
xmlChar *content;
if (!strcmp((const char *) attr_node->name, config_element_name)) {
xmlChar *content;
/* name */
content = xmlNodeGetContent(attr_node);
/* name */
content = xmlNodeGetContent(attr_node);
- name_len = strlen((char *) content);
- if (name_len >= LTTNG_SYMBOL_NAME_LEN) {
- WARN("Channel name too long.");
+ ret = lttng_strncpy(channel->name,
+ (const char *) content,
+ LTTNG_SYMBOL_NAME_LEN);
+ if (ret == -1) {
+ WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
+ (const char *) content,
+ strlen((const char *) content),
+ LTTNG_SYMBOL_NAME_LEN);
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
free(content);
goto end;
}
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
free(content);
goto end;
}
-
- strncpy(channel->name, (const char *) content, name_len);
free(content);
} else if (!strcmp((const char *) attr_node->name,
config_element_enabled)) {
free(content);
} else if (!strcmp((const char *) attr_node->name,
config_element_enabled)) {
} else if (!strcmp((const char *) perf_attr_node->name,
config_element_name)) {
xmlChar *content;
} else if (!strcmp((const char *) perf_attr_node->name,
config_element_name)) {
xmlChar *content;
/* name */
content = xmlNodeGetContent(perf_attr_node);
/* name */
content = xmlNodeGetContent(perf_attr_node);
- name_len = strlen((char *) content);
- if (name_len >= LTTNG_SYMBOL_NAME_LEN) {
- WARN("perf context name too long.");
+ ret = lttng_strncpy(context.u.perf_counter.name,
+ (const char *) content,
+ LTTNG_SYMBOL_NAME_LEN);
+ if (ret == -1) {
+ WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
+ (const char *) content,
+ strlen((const char *) content),
+ LTTNG_SYMBOL_NAME_LEN);
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
free(content);
goto end;
}
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
free(content);
goto end;
}
-
- strncpy(context.u.perf_counter.name, (const char *) content,
- name_len);