mirror of
https://github.com/minetest/minetest.git
synced 2024-11-26 17:43:45 +01:00
lua: apply patch for "read overflow in 'l_strcmp'"
<https://lua.org/bugs.html#5.4.6-1> (minimal port of changes)
This commit is contained in:
parent
77ac20a66b
commit
837aab0e98
@ -209,14 +209,15 @@ static int l_strcmp (const TString *ls, const TString *rs) {
|
|||||||
int temp = strcoll(l, r);
|
int temp = strcoll(l, r);
|
||||||
if (temp != 0) return temp;
|
if (temp != 0) return temp;
|
||||||
else { /* strings are equal up to a `\0' */
|
else { /* strings are equal up to a `\0' */
|
||||||
size_t len = strlen(l); /* index of first `\0' in both strings */
|
size_t zl1 = strlen(l); /* index of first '\0' in 'l' */
|
||||||
if (len == lr) /* r is finished? */
|
size_t zl2 = strlen(r); /* index of first '\0' in 'r' */
|
||||||
return (len == ll) ? 0 : 1;
|
if (zl2 == lr) /* 'r' is finished? */
|
||||||
else if (len == ll) /* l is finished? */
|
return (zl1 == ll) ? 0 : 1; /* check 'l' */
|
||||||
return -1; /* l is smaller than r (because r is not finished) */
|
else if (zl1 == ll) /* 'l' is finished? */
|
||||||
/* both strings longer than `len'; go on comparing (after the `\0') */
|
return -1; /* 'l' is less than 'r' ('r' is not finished) */
|
||||||
len++;
|
/* both strings longer than 'zl'; go on comparing after the '\0' */
|
||||||
l += len; ll -= len; r += len; lr -= len;
|
zl1++; zl2++;
|
||||||
|
l += zl1; ll -= zl1; r += zl2; lr -= zl2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user