1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-24 09:53:10 +03:00

Fix a buffer-overflow problem in the randStr function (used only for testing). (CVS 1182)

FossilOrigin-Name: 42c79edc2e8d1051b3bca915b4b205c601b8077f
This commit is contained in:
drh
2004-01-16 13:58:18 +00:00
parent d1bec47a3d
commit 1dba727946
3 changed files with 10 additions and 9 deletions

View File

@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.35 2004/01/02 13:17:49 drh Exp $
** $Id: func.c,v 1.36 2004/01/16 13:58:18 drh Exp $
*/
#include <ctype.h>
#include <math.h>
@@ -358,7 +358,7 @@ static void randStr(sqlite_func *context, int argc, const char **argv){
if( argc>=2 ){
iMax = atoi(argv[1]);
if( iMax<iMin ) iMax = iMin;
if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf);
if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf)-1;
}else{
iMax = 50;
}
@@ -367,6 +367,7 @@ static void randStr(sqlite_func *context, int argc, const char **argv){
r = sqliteRandomInteger() & 0x7fffffff;
n += r%(iMax + 1 - iMin);
}
assert( n<sizeof(zBuf) );
r = 0;
for(i=0; i<n; i++){
r = (r + sqliteRandomByte())% (sizeof(zSrc)-1);