diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2025-10-10 15:28:41 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2025-10-10 15:28:41 -0300 |
| commit | 7a92f3f99a26d9e51be40b744ed4fab0b50ecaa5 (patch) | |
| tree | d50948f6b4bebdd23a56ac00c96ee8c47c574d82 /lundump.c | |
| parent | 3347c9d32d4d91b6139bff475c78cf0c4796e2a7 (diff) | |
| download | lua-7a92f3f99a26d9e51be40b744ed4fab0b50ecaa5.tar.gz lua-7a92f3f99a26d9e51be40b744ed4fab0b50ecaa5.tar.bz2 lua-7a92f3f99a26d9e51be40b744ed4fab0b50ecaa5.zip | |
Change in dumping of NULL strings
When dumping a string, adding 2 to its size may overflow a size_t for
external strings, which may not have a header. (Adding 1 is Ok, because
all strings end with a '\0' not included in their size.) The new method
for saving NULL strings code them as a repeated string, using the
reserved index 0.
Diffstat (limited to '')
| -rw-r--r-- | lundump.c | 12 |
1 files changed, 6 insertions, 6 deletions
| @@ -147,20 +147,20 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { | |||
| 147 | TString *ts; | 147 | TString *ts; |
| 148 | TValue sv; | 148 | TValue sv; |
| 149 | size_t size = loadSize(S); | 149 | size_t size = loadSize(S); |
| 150 | if (size == 0) { /* no string? */ | 150 | if (size == 0) { /* previously saved string? */ |
| 151 | lua_assert(*sl == NULL); /* must be prefilled */ | ||
| 152 | return; | ||
| 153 | } | ||
| 154 | else if (size == 1) { /* previously saved string? */ | ||
| 155 | lua_Unsigned idx = loadVarint(S, LUA_MAXUNSIGNED); /* get its index */ | 151 | lua_Unsigned idx = loadVarint(S, LUA_MAXUNSIGNED); /* get its index */ |
| 156 | TValue stv; | 152 | TValue stv; |
| 153 | if (idx == 0) { /* no string? */ | ||
| 154 | lua_assert(*sl == NULL); /* must be prefilled */ | ||
| 155 | return; | ||
| 156 | } | ||
| 157 | if (novariant(luaH_getint(S->h, l_castU2S(idx), &stv)) != LUA_TSTRING) | 157 | if (novariant(luaH_getint(S->h, l_castU2S(idx), &stv)) != LUA_TSTRING) |
| 158 | error(S, "invalid string index"); | 158 | error(S, "invalid string index"); |
| 159 | *sl = ts = tsvalue(&stv); /* get its value */ | 159 | *sl = ts = tsvalue(&stv); /* get its value */ |
| 160 | luaC_objbarrier(L, p, ts); | 160 | luaC_objbarrier(L, p, ts); |
| 161 | return; /* do not save it again */ | 161 | return; /* do not save it again */ |
| 162 | } | 162 | } |
| 163 | else if ((size -= 2) <= LUAI_MAXSHORTLEN) { /* short string? */ | 163 | else if ((size -= 1) <= LUAI_MAXSHORTLEN) { /* short string? */ |
| 164 | char buff[LUAI_MAXSHORTLEN + 1]; /* extra space for '\0' */ | 164 | char buff[LUAI_MAXSHORTLEN + 1]; /* extra space for '\0' */ |
| 165 | loadVector(S, buff, size + 1); /* load string into buffer */ | 165 | loadVector(S, buff, size + 1); /* load string into buffer */ |
| 166 | *sl = ts = luaS_newlstr(L, buff, size); /* create string */ | 166 | *sl = ts = luaS_newlstr(L, buff, size); /* create string */ |
