aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorXi Wang <xi.wang@gmail.com>2013-01-22 17:49:29 -0500
committerMichael Niedermayer <michaelni@gmx.at>2013-01-23 05:55:19 +0100
commite163d884ef6ccc52f02a176105098d15c451d6af (patch)
treee90d9cd462dd6e1e0b5095b5a72a4fcd30ef985c /libavformat
parent56cc629a645e479c233750a60a35264b4aa9a651 (diff)
downloadffmpeg-e163d884ef6ccc52f02a176105098d15c451d6af.tar.gz
rtmp: fix multiple broken overflow checks
Sanity checks like `data + size >= data_end || data + size < data' are broken, because `data + size < data' assumes pointer overflow, which is undefined behavior in C. Many compilers such as gcc/clang optimize such checks away. Use `size < 0 || size >= data_end - data' instead. Signed-off-by: Xi Wang <xi.wang@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 902cfe2f74d777a7dc20ac68f2393b9f84b790c1) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/rtmppkt.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c
index 4b6d549f74..5e75e3bd27 100644
--- a/libavformat/rtmppkt.c
+++ b/libavformat/rtmppkt.c
@@ -278,11 +278,11 @@ int ff_amf_tag_size(const uint8_t *data, const uint8_t *data_end)
data++;
break;
}
- if (data + size >= data_end || data + size < data)
+ if (size < 0 || size >= data_end - data)
return -1;
data += size;
t = ff_amf_tag_size(data, data_end);
- if (t < 0 || data + t >= data_end)
+ if (t < 0 || t >= data_end - data)
return -1;
data += t;
}
@@ -311,7 +311,7 @@ int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end,
int size = bytestream_get_be16(&data);
if (!size)
break;
- if (data + size >= data_end || data + size < data)
+ if (size < 0 || size >= data_end - data)
return -1;
data += size;
if (size == namelen && !memcmp(data-size, name, namelen)) {
@@ -332,7 +332,7 @@ int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end,
return 0;
}
len = ff_amf_tag_size(data, data_end);
- if (len < 0 || data + len >= data_end || data + len < data)
+ if (len < 0 || len >= data_end - data)
return -1;
data += len;
}
@@ -403,13 +403,13 @@ static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *d
data++;
break;
}
- if (data + size >= data_end || data + size < data)
+ if (size < 0 || size >= data_end - data)
return;
data += size;
av_log(ctx, AV_LOG_DEBUG, " %s: ", buf);
ff_amf_tag_contents(ctx, data, data_end);
t = ff_amf_tag_size(data, data_end);
- if (t < 0 || data + t >= data_end)
+ if (t < 0 || t >= data_end - data)
return;
data += t;
}