summaryrefslogtreecommitdiffstats
path: root/runtime/vsprintf.c
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2010-02-15 21:27:37 -0800
committerJosh Stone <jistone@redhat.com>2010-02-16 15:55:01 -0800
commitd9f58253e30ea80e57d8f54e41e9cd114cc13973 (patch)
tree557c38cd069499be0defe734595af161a166bd98 /runtime/vsprintf.c
parent4fa8e6497405fd4f121a3eee0c6d772aaeeef6d8 (diff)
downloadsystemtap-steved-d9f58253e30ea80e57d8f54e41e9cd114cc13973.tar.gz
systemtap-steved-d9f58253e30ea80e57d8f54e41e9cd114cc13973.tar.xz
systemtap-steved-d9f58253e30ea80e57d8f54e41e9cd114cc13973.zip
Use clamping to more easily normalize input values
The kernel has min/max/clamp macros to make range comparisons easier. Clamp is a newer invention, but we can define it for older kernels in terms of min and max.
Diffstat (limited to 'runtime/vsprintf.c')
-rw-r--r--runtime/vsprintf.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/runtime/vsprintf.c b/runtime/vsprintf.c
index 5875d509..3f5f2745 100644
--- a/runtime/vsprintf.c
+++ b/runtime/vsprintf.c
@@ -269,7 +269,7 @@ static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* get field width */
field_width = -1;
if (isdigit(*fmt_copy))
- field_width = skip_atoi(&fmt_copy);
+ field_width = clamp(skip_atoi(&fmt_copy), 0, STP_BUFFER_SIZE);
else if (*fmt_copy == '*') {
++fmt_copy;
/* it's the next argument */
@@ -278,6 +278,7 @@ static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
field_width = -field_width;
flags |= STP_LEFT;
}
+ field_width = clamp(field_width, 0, STP_BUFFER_SIZE);
}
/* get the precision */
@@ -291,8 +292,7 @@ static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* it's the next argument */
precision = va_arg(args_copy, int);
}
- if (precision < 0)
- precision = 0;
+ precision = clamp(precision, 0, STP_BUFFER_SIZE);
}
/* get the conversion qualifier */
@@ -511,7 +511,7 @@ static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* get field width */
field_width = -1;
if (isdigit(*fmt))
- field_width = skip_atoi(&fmt);
+ field_width = clamp(skip_atoi(&fmt), 0, (int)size);
else if (*fmt == '*') {
++fmt;
/* it's the next argument */
@@ -520,6 +520,7 @@ static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
field_width = -field_width;
flags |= STP_LEFT;
}
+ field_width = clamp(field_width, 0, (int)size);
}
/* get the precision */
@@ -533,8 +534,7 @@ static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* it's the next argument */
precision = va_arg(args, int);
}
- if (precision < 0)
- precision = 0;
+ precision = clamp(precision, 0, (int)size);
}
/* get the conversion qualifier */