for (pos = 0; pos < i; pos++) {
char *p, *k, *v;
+ size_t len;
key = PyList_GetItem(keys, pos);
val = PyList_GetItem(vals, pos);
/* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
#endif
- p = PyMem_NEW(char, PyString_Size(key)+PyString_Size(val) + 2);
+ len = PyString_Size(key) + PyString_Size(val) + 2;
+ p = PyMem_NEW(char, len);
if (p == NULL) {
PyErr_NoMemory();
goto fail_2;
}
- sprintf(p, "%s=%s", k, v);
+ PyOS_snprintf(p, len, "%s=%s", k, v);
envlist[envc++] = p;
#if defined(PYOS_OS2)
}
for (pos = 0; pos < i; pos++) {
char *p, *k, *v;
+ size_t len;
key = PyList_GetItem(keys, pos);
val = PyList_GetItem(vals, pos);
{
goto fail_2;
}
- p = PyMem_NEW(char, PyString_Size(key)+PyString_Size(val) + 2);
+ len = PyString_Size(key) + PyString_Size(val) + 2;
+ p = PyMem_NEW(char, len);
if (p == NULL) {
PyErr_NoMemory();
goto fail_2;
}
- sprintf(p, "%s=%s", k, v);
+ PyOS_snprintf(p, len, "%s=%s", k, v);
envlist[envc++] = p;
}
envlist[envc] = 0;
char *s1, *s2;
char *new;
PyObject *newstr;
+ size_t len;
if (!PyArg_ParseTuple(args, "ss:putenv", &s1, &s2))
return NULL;
#endif
/* XXX This can leak memory -- not easy to fix :-( */
- newstr = PyString_FromStringAndSize(NULL, strlen(s1) + strlen(s2) + 2);
+ len = strlen(s1) + strlen(s2) + 2;
+ /* len includes space for a trailing \0; the size arg to
+ PyString_FromStringAndSize does not count that */
+ newstr = PyString_FromStringAndSize(NULL, (int)len - 1);
if (newstr == NULL)
return PyErr_NoMemory();
new = PyString_AS_STRING(newstr);
- (void) sprintf(new, "%s=%s", s1, s2);
+ PyOS_snprintf(new, len, "%s=%s", s1, s2);
if (putenv(new)) {
posix_error();
return NULL;