summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-06-25 17:54:27 -0700
committerScott Shawcroft <scott@tannewt.org>2019-06-25 17:54:27 -0700
commit2494bfdc8626aadb7d3197d165daf2569f3a8db1 (patch)
treea262e8dabad6dbd3351c72caf93caf2a038d3944
parent77355cbb2f5a3cc2b48468955774a830f18ecf39 (diff)
Validate raw code and mpy read length
-rw-r--r--locale/ID.po6
-rw-r--r--locale/circuitpython.pot6
-rw-r--r--locale/de_DE.po6
-rw-r--r--locale/en_US.po6
-rw-r--r--locale/en_x_pirate.po6
-rw-r--r--locale/es.po6
-rw-r--r--locale/fil.po6
-rw-r--r--locale/fr.po6
-rw-r--r--locale/it_IT.po6
-rw-r--r--locale/pl.po6
-rw-r--r--locale/pt_BR.po6
-rw-r--r--locale/zh_Latn_pinyin.po6
-rw-r--r--py/emitglue.c7
-rw-r--r--py/persistentcode.c29
14 files changed, 83 insertions, 25 deletions
diff --git a/locale/ID.po b/locale/ID.po
index 9545845cd..60d882bc6 100644
--- a/locale/ID.po
+++ b/locale/ID.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -464,6 +464,10 @@ msgstr ""
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot
index 7e9f65581..1c48658ec 100644
--- a/locale/circuitpython.pot
+++ b/locale/circuitpython.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -454,6 +454,10 @@ msgstr ""
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/de_DE.po b/locale/de_DE.po
index 5e948cb6b..2b3b25ce7 100644
--- a/locale/de_DE.po
+++ b/locale/de_DE.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: Pascal Deneaux\n"
"Language-Team: Sebastian Plamauer, Pascal Deneaux\n"
@@ -458,6 +458,10 @@ msgstr "Der Befehl muss ein int zwischen 0 und 255 sein"
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/en_US.po b/locale/en_US.po
index a50263d9f..1b5c36010 100644
--- a/locale/en_US.po
+++ b/locale/en_US.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -454,6 +454,10 @@ msgstr ""
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po
index 443204fb5..12a134a7d 100644
--- a/locale/en_x_pirate.po
+++ b/locale/en_x_pirate.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: @sommersoft, @MrCertainly\n"
@@ -458,6 +458,10 @@ msgstr ""
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/es.po b/locale/es.po
index 2135b7e77..63dae87de 100644
--- a/locale/es.po
+++ b/locale/es.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2018-08-24 22:56-0500\n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -470,6 +470,10 @@ msgstr "Bytes debe estar entre 0 y 255."
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/fil.po b/locale/fil.po
index 8f3996d16..393c67ad1 100644
--- a/locale/fil.po
+++ b/locale/fil.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2018-12-20 22:15-0800\n"
"Last-Translator: Timothy <me@timothygarcia.ca>\n"
"Language-Team: fil\n"
@@ -463,6 +463,10 @@ msgstr "Sa gitna ng 0 o 255 dapat ang bytes."
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/fr.po b/locale/fr.po
index 6ee7b4d5a..a64deeace 100644
--- a/locale/fr.po
+++ b/locale/fr.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2019-04-14 20:05+0100\n"
"Last-Translator: Pierrick Couturier <arofarn@arofarn.info>\n"
"Language-Team: fr\n"
@@ -469,6 +469,10 @@ msgstr "La commande doit être un entier entre 0 et 255"
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/it_IT.po b/locale/it_IT.po
index ef1e306a1..52c229e03 100644
--- a/locale/it_IT.po
+++ b/locale/it_IT.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2018-10-02 16:27+0200\n"
"Last-Translator: Enrico Paganin <enrico.paganin@mail.com>\n"
"Language-Team: \n"
@@ -464,6 +464,10 @@ msgstr "I byte devono essere compresi tra 0 e 255"
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/pl.po b/locale/pl.po
index 09187eb67..bdb6f4795 100644
--- a/locale/pl.po
+++ b/locale/pl.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2019-03-19 18:37-0700\n"
"Last-Translator: Radomir Dopieralski <circuitpython@sheep.art.pl>\n"
"Language-Team: pl\n"
@@ -457,6 +457,10 @@ msgstr "Komenda musi być int pomiędzy 0 a 255"
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/pt_BR.po b/locale/pt_BR.po
index 734491dd7..8b61c23b8 100644
--- a/locale/pt_BR.po
+++ b/locale/pt_BR.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2018-10-02 21:14-0000\n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -460,6 +460,10 @@ msgstr "Os bytes devem estar entre 0 e 255."
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po
index 8ad03c968..314591560 100644
--- a/locale/zh_Latn_pinyin.po
+++ b/locale/zh_Latn_pinyin.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: circuitpython-cn\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-06-25 16:50-0700\n"
+"POT-Creation-Date: 2019-06-25 17:53-0700\n"
"PO-Revision-Date: 2019-04-13 10:10-0700\n"
"Last-Translator: hexthat\n"
"Language-Team: Chinese Hanyu Pinyin\n"
@@ -458,6 +458,10 @@ msgstr "Mìnglìng bìxū shì 0 dào 255 zhī jiān de int"
msgid "Corrupt .mpy file"
msgstr ""
+#: py/emitglue.c
+msgid "Corrupt raw code"
+msgstr ""
+
#: ports/nrf/common-hal/bleio/UUID.c
#, c-format
msgid "Could not decode ble_uuid, err 0x%04x"
diff --git a/py/emitglue.c b/py/emitglue.c
index 74bf8ddca..7708689dd 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -142,11 +142,12 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar
fun = mp_obj_new_fun_asm(rc->n_pos_args, rc->data.u_native.fun_data, rc->data.u_native.type_sig);
break;
#endif
- default:
- // rc->kind should always be set and BYTECODE is the only remaining case
- assert(rc->kind == MP_CODE_BYTECODE);
+ case MP_CODE_BYTECODE:
fun = mp_obj_new_fun_bc(def_args, def_kw_args, rc->data.u_byte.bytecode, rc->data.u_byte.const_table);
break;
+ default:
+ // All other kinds are invalid.
+ mp_raise_RuntimeError(translate("Corrupt raw code"));
}
// check for generator functions and if so wrap in generator object
diff --git a/py/persistentcode.c b/py/persistentcode.c
index c0358faa0..eb69bd407 100644
--- a/py/persistentcode.c
+++ b/py/persistentcode.c
@@ -102,20 +102,35 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_
#include "py/parsenum.h"
+STATIC void raise_corrupt_mpy(void) {
+ mp_raise_RuntimeError(translate("Corrupt .mpy file"));
+}
+
STATIC int read_byte(mp_reader_t *reader) {
- return reader->readbyte(reader->data);
+ mp_uint_t b = reader->readbyte(reader->data);
+ if (b == MP_READER_EOF) {
+ raise_corrupt_mpy();
+ }
+ return b;
}
STATIC void read_bytes(mp_reader_t *reader, byte *buf, size_t len) {
while (len-- > 0) {
- *buf++ = reader->readbyte(reader->data);
+ mp_uint_t b =reader->readbyte(reader->data);
+ if (b == MP_READER_EOF) {
+ raise_corrupt_mpy();
+ }
+ *buf++ = b;
}
}
STATIC size_t read_uint(mp_reader_t *reader) {
size_t unum = 0;
for (;;) {
- byte b = reader->readbyte(reader->data);
+ mp_uint_t b = reader->readbyte(reader->data);
+ if (b == MP_READER_EOF) {
+ raise_corrupt_mpy();
+ }
unum = (unum << 7) | (b & 0x7f);
if ((b & 0x80) == 0) {
break;
@@ -128,12 +143,6 @@ STATIC qstr load_qstr(mp_reader_t *reader) {
size_t len = read_uint(reader);
char str[len];
read_bytes(reader, (byte*)str, len);
- // Validate the QSTRs by ensuring they do not contain any null terminations. They are length encoded instead.
- for (size_t i = 0; i < len; i++) {
- if (str[i] == '\0') {
- mp_raise_RuntimeError(translate("Corrupt .mpy file"));
- }
- }
qstr qst = qstr_from_strn(str, len);
return qst;
}
@@ -155,7 +164,7 @@ STATIC mp_obj_t load_obj(mp_reader_t *reader) {
return mp_parse_num_decimal(vstr.buf, vstr.len, obj_type == 'c', false, NULL);
}
}
- mp_raise_RuntimeError(translate("Corrupt .mpy file"));
+ raise_corrupt_mpy();
return MP_OBJ_FROM_PTR(&mp_const_none_obj);
}