/*
* Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
- * Copyright (c) 2016-2017 The strace developers.
+ * Copyright (c) 2016-2018 The strace developers.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
static int
sigstr_to_uint(const char *s)
{
- int i;
-
if (*s >= '0' && *s <= '9')
return string_to_uint_upto(s, 255);
if (strncasecmp(s, "SIG", 3) == 0)
s += 3;
- for (i = 0; i <= 255; ++i) {
+ for (int i = 0; i <= 255; ++i) {
const char *name = signame(i);
if (strncasecmp(name, "SIG", 3) != 0)
static int
find_errno_by_name(const char *name)
{
- unsigned int i;
-
- for (i = 1; i < nerrnos; ++i) {
+ for (unsigned int i = 1; i < nerrnos; ++i) {
if (errnoent[i] && (strcasecmp(name, errnoent[i]) == 0))
return i;
}
const bool fault_tokens_only)
{
const char *val;
- int intval;
+ kernel_long_t intval;
if ((val = STR_STRIP_PREFIX(token, "when=")) != token) {
/*
&& (val = STR_STRIP_PREFIX(token, "retval=")) != token) {
if (fopts->data.flags & INJECT_F_RETVAL)
return false;
- intval = string_to_uint(val);
+ intval = string_to_kulong(val);
if (intval < 0)
return false;
+
+#if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG && !HAVE_ARCH_DEDICATED_ERR_REG
+ if ((int) intval != intval)
+ error_msg("Injected return value %" PRI_kld " will be"
+ " clipped to %d in compat personality",
+ intval, (int) intval);
+
+ if ((int) intval < 0 && (int) intval >= -MAX_ERRNO_VALUE)
+ error_msg("Inadvertent injection of error %d is"
+ " possible in compat personality for"
+ " retval=%" PRI_kld,
+ -(int) intval, intval);
+#endif
+
fopts->data.rval = intval;
fopts->data.flags |= INJECT_F_RETVAL;
} else if (!fault_tokens_only
return true;
}
-static char *
+static const char *
parse_inject_expression(char *const str,
struct inject_opts *const fopts,
const bool fault_tokens_only)
{
+ if (str[0] == '\0' || str[0] == ':')
+ return "";
+
char *saveptr = NULL;
- char *name = NULL;
- char *token;
+ const char *name = strtok_r(str, ":", &saveptr);
- for (token = strtok_r(str, ":", &saveptr); token;
- token = strtok_r(NULL, ":", &saveptr)) {
- if (!name)
- name = token;
- else if (!parse_inject_token(token, fopts, fault_tokens_only))
+ char *token;
+ while ((token = strtok_r(NULL, ":", &saveptr))) {
+ if (!parse_inject_token(token, fopts, fault_tokens_only))
return NULL;
}
.step = 1
};
char *copy = xstrdup(str);
- char *name = parse_inject_expression(copy, &opts, fault_tokens_only);
+ const char *name =
+ parse_inject_expression(copy, &opts, fault_tokens_only);
if (!name)
error_msg_and_die("invalid %s '%s'", description, str);
+ struct number_set *tmp_set =
+ alloc_number_set_array(SUPPORTED_PERSONALITIES);
+ qualify_syscall_tokens(name, tmp_set);
+
+ free(copy);
+
/* If neither of retval, error, or signal is specified, then ... */
if (!opts.data.flags) {
if (fault_tokens_only) {
}
}
- struct number_set *tmp_set =
- alloc_number_set_array(SUPPORTED_PERSONALITIES);
- qualify_syscall_tokens(name, tmp_set);
-
- free(copy);
-
/*
* Initialize inject_vec according to tmp_set.
* Merge tmp_set into inject_set.
*/
- unsigned int p;
- for (p = 0; p < SUPPORTED_PERSONALITIES; ++p) {
+ for (unsigned int p = 0; p < SUPPORTED_PERSONALITIES; ++p) {
if (number_set_array_is_empty(tmp_set, p))
continue;
sizeof(*inject_vec[p]));
}
- unsigned int i;
- for (i = 0; i < nsyscall_vec[p]; ++i) {
+ for (unsigned int i = 0; i < nsyscall_vec[p]; ++i) {
if (is_number_in_set_array(i, tmp_set, p)) {
add_number_to_set_array(i, inject_set, p);
inject_vec[p][i] = opts;
qualify(const char *str)
{
const struct qual_options *opt = qual_options;
- unsigned int i;
- for (i = 0; i < ARRAY_SIZE(qual_options); ++i) {
+ for (unsigned int i = 0; i < ARRAY_SIZE(qual_options); ++i) {
const char *name = qual_options[i].name;
const size_t len = strlen(name);
const char *val = str_strip_prefix_len(str, name, len);