mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
Fix various potential buffer overrun problems.
This commit is contained in:
parent
138d72f64b
commit
6c849697fd
1 changed files with 18 additions and 9 deletions
|
@ -167,8 +167,12 @@ extern char *getprogramname();
|
||||||
|
|
||||||
#endif /* DYNAMIC_LINK */
|
#endif /* DYNAMIC_LINK */
|
||||||
|
|
||||||
/* Magic word to reject .pyc files generated by other Python versions */
|
/* Max length of module suffix searched for -- accommodates "module.so" */
|
||||||
|
#ifndef MAXSUFFIXSIZE
|
||||||
|
#define MAXSUFFIXSIZE 10
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Magic word to reject .pyc files generated by other Python versions */
|
||||||
#define MAGIC 0x999903L /* Increment by one for each incompatible change */
|
#define MAGIC 0x999903L /* Increment by one for each incompatible change */
|
||||||
|
|
||||||
static object *modules;
|
static object *modules;
|
||||||
|
@ -355,7 +359,7 @@ load_dynamic_module(name, namebuf, m, m_ret)
|
||||||
char buf[256];
|
char buf[256];
|
||||||
if (verbose)
|
if (verbose)
|
||||||
perror(namebuf);
|
perror(namebuf);
|
||||||
sprintf(buf,"Failed to load %s", namebuf);
|
sprintf(buf, "Failed to load %.200s", namebuf);
|
||||||
err_setstr(ImportError, buf);
|
err_setstr(ImportError, buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -396,7 +400,7 @@ get_module(m, name, m_ret)
|
||||||
char *name;
|
char *name;
|
||||||
object **m_ret;
|
object **m_ret;
|
||||||
{
|
{
|
||||||
int err, npath, i, len;
|
int err, npath, i, len, namelen;
|
||||||
long magic;
|
long magic;
|
||||||
long mtime, pyc_mtime;
|
long mtime, pyc_mtime;
|
||||||
char namebuf[MAXPATHLEN+1];
|
char namebuf[MAXPATHLEN+1];
|
||||||
|
@ -413,16 +417,21 @@ get_module(m, name, m_ret)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
npath = getlistsize(path);
|
npath = getlistsize(path);
|
||||||
|
namelen = strlen(name);
|
||||||
for (i = 0; i < npath; i++) {
|
for (i = 0; i < npath; i++) {
|
||||||
v = getlistitem(path, i);
|
v = getlistitem(path, i);
|
||||||
if (!is_stringobject(v))
|
if (!is_stringobject(v))
|
||||||
continue;
|
continue;
|
||||||
strcpy(namebuf, getstringvalue(v));
|
|
||||||
len = getstringsize(v);
|
len = getstringsize(v);
|
||||||
|
if (len + 1 + namelen + MAXSUFFIXSIZE >= MAXPATHLEN)
|
||||||
|
continue; /* Too long */
|
||||||
|
strcpy(namebuf, getstringvalue(v));
|
||||||
|
if (strlen(namebuf) != len)
|
||||||
|
continue; /* v contains '\0' */
|
||||||
if (len > 0 && namebuf[len-1] != SEP)
|
if (len > 0 && namebuf[len-1] != SEP)
|
||||||
namebuf[len++] = SEP;
|
namebuf[len++] = SEP;
|
||||||
strcpy(namebuf+len, name);
|
strcpy(namebuf+len, name);
|
||||||
len += strlen(name);
|
len += namelen;
|
||||||
for (fdp = filetab; fdp->suffix != NULL; fdp++) {
|
for (fdp = filetab; fdp->suffix != NULL; fdp++) {
|
||||||
strcpy(namebuf+len, fdp->suffix);
|
strcpy(namebuf+len, fdp->suffix);
|
||||||
if (verbose > 1)
|
if (verbose > 1)
|
||||||
|
@ -435,7 +444,7 @@ get_module(m, name, m_ret)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
sprintf(namebuf, "No module named %s", name);
|
sprintf(namebuf, "No module named %.200s", name);
|
||||||
err_setstr(ImportError, namebuf);
|
err_setstr(ImportError, namebuf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -761,9 +770,9 @@ void aix_loaderror(char *namebuf)
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LOAD_ERRTAB_LEN (sizeof(load_errtab)/sizeof(load_errtab[0]))
|
#define LOAD_ERRTAB_LEN (sizeof(load_errtab)/sizeof(load_errtab[0]))
|
||||||
#define ERRBUF_APPEND(s) strncat(errbuf, s, sizeof(errbuf))
|
#define ERRBUF_APPEND(s) strncat(errbuf, s, sizeof(errbuf)-strlen(errbuf)-1)
|
||||||
|
|
||||||
sprintf(errbuf, " from module %s ", namebuf);
|
sprintf(errbuf, " from module %.200s ", namebuf);
|
||||||
|
|
||||||
if (!loadquery(1, &message[0], sizeof(message)))
|
if (!loadquery(1, &message[0], sizeof(message)))
|
||||||
ERRBUF_APPEND(strerror(errno));
|
ERRBUF_APPEND(strerror(errno));
|
||||||
|
@ -777,7 +786,7 @@ void aix_loaderror(char *namebuf)
|
||||||
ERRBUF_APPEND(message[i]);
|
ERRBUF_APPEND(message[i]);
|
||||||
ERRBUF_APPEND("\n");
|
ERRBUF_APPEND("\n");
|
||||||
}
|
}
|
||||||
errbuf[strlen(errbuf)-1] = '\0' ; /* trim off last newline */
|
errbuf[strlen(errbuf)-1] = '\0'; /* trim off last newline */
|
||||||
err_setstr(ImportError, errbuf);
|
err_setstr(ImportError, errbuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue