summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-04-28 14:58:35 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-04-28 14:58:35 +0200
commitb5d43b81a8abdf17bc3aa585a66215ebe3ba3671 (patch)
tree2b1f8e75bd7c2cbaa66a117cc88712c26763b31f /util.c
parente0bc222263cf47a43e1b26d55edb2ffadc8ccbff (diff)
downloadstrace-b5d43b81a8abdf17bc3aa585a66215ebe3ba3671.tar.gz
strace-b5d43b81a8abdf17bc3aa585a66215ebe3ba3671.tar.bz2
strace-b5d43b81a8abdf17bc3aa585a66215ebe3ba3671.tar.xz
Fix printstr's len parameter width
We often pass syscall params and other long-sized values as printstr(len). Truncating them to int may be a bad thing. * defs.h: Change len parameter's type from int to long in string_quote and printstr function declarations. * util.c (string_quote): Special-case only len==-1, not all len<0. (printstr): Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/util.c b/util.c
index ea03685..d347bd8 100644
--- a/util.c
+++ b/util.c
@@ -372,21 +372,21 @@ printuid(const char *text, unsigned long uid)
/*
* Quote string `instr' of length `size'
* Write up to (3 + `size' * 4) bytes to `outstr' buffer.
- * If `len' < 0, treat `instr' as a NUL-terminated string
+ * If `len' is -1, treat `instr' as a NUL-terminated string
* and quote at most (`size' - 1) bytes.
*
- * Returns 0 if len < 0 and NUL was seen, 1 otherwise.
+ * Returns 0 if len == -1 and NUL was seen, 1 otherwise.
* Note that if len >= 0, always returns 1.
*/
int
-string_quote(const char *instr, char *outstr, int len, int size)
+string_quote(const char *instr, char *outstr, long len, int size)
{
const unsigned char *ustr = (const unsigned char *) instr;
char *s = outstr;
int usehex, c, i, eol;
eol = 0x100; /* this can never match a char */
- if (len < 0) {
+ if (len == -1) {
size--;
eol = '\0';
}
@@ -486,7 +486,7 @@ string_quote(const char *instr, char *outstr, int len, int size)
*s = '\0';
/* Return zero if we printed entire ASCIZ string (didn't truncate it) */
- if (len < 0 && ustr[i] == '\0') {
+ if (len == -1 && ustr[i] == '\0') {
/* We didn't see NUL yet (otherwise we'd jump to 'asciz_ended')
* but next char is NUL.
*/
@@ -551,7 +551,7 @@ printpath(struct tcb *tcp, long addr)
* If string length exceeds `max_strlen', append `...' to the output.
*/
void
-printstr(struct tcb *tcp, long addr, int len)
+printstr(struct tcb *tcp, long addr, long len)
{
static char *str = NULL;
static char *outstr;
@@ -576,7 +576,7 @@ printstr(struct tcb *tcp, long addr, int len)
die_out_of_memory();
}
- if (len < 0) {
+ if (len == -1) {
/*
* Treat as a NUL-terminated string: fetch one byte more
* because string_quote() quotes one byte less.
@@ -588,7 +588,9 @@ printstr(struct tcb *tcp, long addr, int len)
}
}
else {
- size = MIN(len, max_strlen);
+ size = max_strlen;
+ if (size > (unsigned long)len)
+ size = (unsigned long)len;
if (umoven(tcp, addr, size, str) < 0) {
tprintf("%#lx", addr);
return;