Index: Modules/getpath.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/getpath.c,v retrieving revision 1.41 diff -C5 -r1.41 getpath.c *** Modules/getpath.c 12 Jan 2002 11:05:06 -0000 1.41 --- Modules/getpath.c 29 Aug 2002 21:17:34 -0000 *************** *** 247,256 **** --- 247,257 ---- /* If PYTHONHOME is set, we believe it unconditionally */ if (home) { char *delim; strncpy(prefix, home, MAXPATHLEN); + prefix[MAXPATHLEN] = '\0'; delim = strchr(prefix, DELIM); if (delim) *delim = '\0'; joinpath(prefix, lib_python); joinpath(prefix, LANDMARK); *************** *** 283,292 **** --- 284,294 ---- reduce(prefix); } while (prefix[0]); /* Look at configure's PREFIX */ strncpy(prefix, PREFIX, MAXPATHLEN); + prefix[MAXPATHLEN] = '\0'; joinpath(prefix, lib_python); joinpath(prefix, LANDMARK); if (ismodule(prefix)) return 1; *************** *** 309,318 **** --- 311,321 ---- delim = strchr(home, DELIM); if (delim) strncpy(exec_prefix, delim+1, MAXPATHLEN); else strncpy(exec_prefix, home, MAXPATHLEN); + exec_prefix[MAXPATHLEN] = '\0'; joinpath(exec_prefix, lib_python); joinpath(exec_prefix, "lib-dynload"); return 1; } *************** *** 336,345 **** --- 339,349 ---- reduce(exec_prefix); } while (exec_prefix[0]); /* Look at configure's EXEC_PREFIX */ strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); + exec_prefix[MAXPATHLEN] = '\0'; joinpath(exec_prefix, lib_python); joinpath(exec_prefix, "lib-dynload"); if (isdir(exec_prefix)) return 1; *************** *** 373,384 **** /* If there is no slash in the argv0 path, then we have to * assume python is on the user's $PATH, since there's no * other way to find a directory to start the search from. If * $PATH isn't exported, you lose. */ ! if (strchr(prog, SEP)) strncpy(progpath, prog, MAXPATHLEN); else if (path) { while (1) { char *delim = strchr(path, DELIM); if (delim) { --- 377,390 ---- /* If there is no slash in the argv0 path, then we have to * assume python is on the user's $PATH, since there's no * other way to find a directory to start the search from. If * $PATH isn't exported, you lose. */ ! if (strchr(prog, SEP)) { strncpy(progpath, prog, MAXPATHLEN); + progpath[MAXPATHLEN] = '\0'; + } else if (path) { while (1) { char *delim = strchr(path, DELIM); if (delim) { *************** *** 386,397 **** if (len > MAXPATHLEN) len = MAXPATHLEN; strncpy(progpath, path, len); *(progpath + len) = '\0'; } ! else strncpy(progpath, path, MAXPATHLEN); joinpath(progpath, prog); if (isxfile(progpath)) break; --- 392,405 ---- if (len > MAXPATHLEN) len = MAXPATHLEN; strncpy(progpath, path, len); *(progpath + len) = '\0'; } ! else { strncpy(progpath, path, MAXPATHLEN); + progpath[MAXPATHLEN] = '\0'; + } joinpath(progpath, prog); if (isxfile(progpath)) break; *************** *** 405,414 **** --- 413,423 ---- else progpath[0] = '\0'; if (progpath[0] != SEP) absolutize(progpath); strncpy(argv0_path, progpath, MAXPATHLEN); + argv0_path[MAXPATHLEN] = '\0'; #ifdef WITH_NEXT_FRAMEWORK /* On Mac OS X we have a special case if we're running from a framework. ** This is because the python home should be set relative to the library, ** which is in the framework, not relative to the executable, which may *************** *** 425,445 **** --- 434,457 ---- ** If we're running with the framework from the build directory we must ** be running the interpreter in the build directory, so we use the ** build-directory-specific logic to find Lib and such. */ strncpy(argv0_path, buf, MAXPATHLEN); + argv0_path[MAXPATHLEN] = '\0'; reduce(argv0_path); joinpath(argv0_path, lib_python); joinpath(argv0_path, LANDMARK); if (!ismodule(argv0_path)) { /* We are in the build directory so use the name of the executable - we know that the absolute path is passed */ strncpy(argv0_path, prog, MAXPATHLEN); + argv0_path[MAXPATHLEN] = '\0'; } else { /* Use the location of the library as the progpath */ strncpy(argv0_path, buf, MAXPATHLEN); + argv0_path[MAXPATHLEN] = '\0'; } } #endif #if HAVE_READLINK *************** *** 447,460 **** char tmpbuffer[MAXPATHLEN+1]; int linklen = readlink(progpath, tmpbuffer, MAXPATHLEN); while (linklen != -1) { /* It's not null terminated! */ tmpbuffer[linklen] = '\0'; ! if (tmpbuffer[0] == SEP) /* tmpbuffer should never be longer than MAXPATHLEN, but extra check does not hurt */ strncpy(argv0_path, tmpbuffer, MAXPATHLEN); else { /* Interpret relative to progpath */ reduce(argv0_path); joinpath(argv0_path, tmpbuffer); } --- 459,474 ---- char tmpbuffer[MAXPATHLEN+1]; int linklen = readlink(progpath, tmpbuffer, MAXPATHLEN); while (linklen != -1) { /* It's not null terminated! */ tmpbuffer[linklen] = '\0'; ! if (tmpbuffer[0] == SEP) { /* tmpbuffer should never be longer than MAXPATHLEN, but extra check does not hurt */ strncpy(argv0_path, tmpbuffer, MAXPATHLEN); + argv0_path[MAXPATHLEN] = '\0'; + } else { /* Interpret relative to progpath */ reduce(argv0_path); joinpath(argv0_path, tmpbuffer); } *************** *** 471,490 **** --- 485,506 ---- if (!(pfound = search_for_prefix(argv0_path, home))) { if (!Py_FrozenFlag) fprintf(stderr, "Could not find platform independent libraries \n"); strncpy(prefix, PREFIX, MAXPATHLEN); + prefix[MAXPATHLEN] = '\0'; joinpath(prefix, lib_python); } else reduce(prefix); if (!(efound = search_for_exec_prefix(argv0_path, home))) { if (!Py_FrozenFlag) fprintf(stderr, "Could not find platform dependent libraries \n"); strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); + exec_prefix[MAXPATHLEN] = '\0'; joinpath(exec_prefix, "lib/lib-dynload"); } /* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */ if ((!pfound || !efound) && !Py_FrozenFlag) *************** *** 576,595 **** */ if (pfound > 0) { reduce(prefix); reduce(prefix); } ! else strncpy(prefix, PREFIX, MAXPATHLEN); if (efound > 0) { reduce(exec_prefix); reduce(exec_prefix); reduce(exec_prefix); } ! else strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); } /* External interface */ --- 592,615 ---- */ if (pfound > 0) { reduce(prefix); reduce(prefix); } ! else { strncpy(prefix, PREFIX, MAXPATHLEN); + prefix[MAXPATHLEN] = '\0'; + } if (efound > 0) { reduce(exec_prefix); reduce(exec_prefix); reduce(exec_prefix); } ! else { strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); + exec_prefix[MAXPATHLEN] = '\0'; + } } /* External interface */ Index: PC/getpathp.c =================================================================== RCS file: /cvsroot/python/python/dist/src/PC/getpathp.c,v retrieving revision 1.28 diff -C5 -r1.28 getpathp.c *** PC/getpathp.c 22 Jul 2002 13:28:21 -0000 1.28 --- PC/getpathp.c 29 Aug 2002 21:17:35 -0000 *************** *** 381,391 **** --- 381,394 ---- #ifdef ALTSEP if (strchr(prog, SEP) || strchr(prog, ALTSEP)) #else if (strchr(prog, SEP)) #endif + { strncpy(progpath, prog, MAXPATHLEN); + progpath[MAXPATHLEN] = '\0'; + } else if (path) { while (1) { char *delim = strchr(path, DELIM); if (delim) { *************** *** 393,404 **** /* ensure we can't overwrite buffer */ len = min(MAXPATHLEN,len); strncpy(progpath, path, len); *(progpath + len) = '\0'; } ! else strncpy(progpath, path, MAXPATHLEN); /* join() is safe for MAXPATHLEN+1 size buffer */ join(progpath, prog); if (exists(progpath)) break; --- 396,409 ---- /* ensure we can't overwrite buffer */ len = min(MAXPATHLEN,len); strncpy(progpath, path, len); *(progpath + len) = '\0'; } ! else { strncpy(progpath, path, MAXPATHLEN); + progpath[MAXPATHLEN] = '\0'; + } /* join() is safe for MAXPATHLEN+1 size buffer */ join(progpath, prog); if (exists(progpath)) break; *************** *** 437,448 **** if (search_for_prefix(argv0_path, LANDMARK)) pythonhome = prefix; else pythonhome = NULL; } ! else strncpy(prefix, pythonhome, MAXPATHLEN); if (envpath && *envpath == '\0') envpath = NULL; --- 442,455 ---- if (search_for_prefix(argv0_path, LANDMARK)) pythonhome = prefix; else pythonhome = NULL; } ! else { strncpy(prefix, pythonhome, MAXPATHLEN); + prefix[MAXPATHLEN] = '\0'; + } if (envpath && *envpath == '\0') envpath = NULL;