diff options
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/adt/filename.c | 4 | ||||
-rw-r--r-- | src/backend/utils/error/elog.c | 6 | ||||
-rw-r--r-- | src/backend/utils/init/postinit.c | 66 | ||||
-rw-r--r-- | src/backend/utils/misc/database.c | 50 |
4 files changed, 66 insertions, 60 deletions
diff --git a/src/backend/utils/adt/filename.c b/src/backend/utils/adt/filename.c index eb705b9f6b4..0a3871280dc 100644 --- a/src/backend/utils/adt/filename.c +++ b/src/backend/utils/adt/filename.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.22 1999/07/17 20:17:55 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.23 1999/10/25 03:07:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -31,7 +31,7 @@ filename_in(char *file) * (shexpand) */ - str = (char *) palloc(MAXPATHLEN * sizeof(*str)); + str = (char *) palloc(MAXPGPATH); str[0] = '\0'; if (file[0] == '~') { diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 342a1029d16..247cf1c724a 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.49 1999/10/06 21:58:09 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.50 1999/10/25 03:07:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -415,7 +415,6 @@ DebugFileOpen(void) if (OutputFileName[0]) { - OutputFileName[MAXPGPATH - 1] = '\0'; if ((fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY, 0666)) < 0) elog(FATAL, "DebugFileOpen: open of %s: %m", @@ -448,7 +447,8 @@ DebugFileOpen(void) fd = fileno(stderr); if (fcntl(fd, F_GETFD, 0) < 0) { - sprintf(OutputFileName, "%s/pg.errors.%d", DataDir, (int) MyProcPid); + snprintf(OutputFileName, MAXPGPATH, "%s%cpg.errors.%d", + DataDir, SEP_CHAR, (int) MyProcPid); fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY, 0666); } if (fd < 0) diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 20db5c34bb7..72c87f16196 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.51 1999/10/06 21:58:10 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.52 1999/10/25 03:07:51 tgl Exp $ * * NOTES * InitPostgres() is the function called from PostgresMain @@ -100,7 +100,7 @@ static void InitMyDatabaseInfo(char *name) { char *path, - myPath[MAXPGPATH + 1]; + myPath[MAXPGPATH]; SetDatabaseName(name); GetRawDatabaseInfo(name, &MyDatabaseId, myPath); @@ -143,10 +143,9 @@ static void VerifySystemDatabase() { char *reason; - /* Failure reason returned by some function. NULL if no failure */ int fd; - char errormsg[1000]; + char errormsg[MAXPGPATH+100]; errormsg[0] = '\0'; @@ -155,20 +154,21 @@ VerifySystemDatabase() #else if ((fd = open(DataDir, O_RDONLY | O_DIROPEN, 0)) == -1) #endif - sprintf(errormsg, "Database system does not exist. " - "PGDATA directory '%s' not found.\n\tNormally, you " - "create a database system by running initdb.", - DataDir); + snprintf(errormsg, sizeof(errormsg), + "Database system does not exist. " + "PGDATA directory '%s' not found.\n\tNormally, you " + "create a database system by running initdb.", + DataDir); else { close(fd); ValidatePgVersion(DataDir, &reason); if (reason != NULL) - sprintf(errormsg, - "InitPostgres could not validate that the database" - " system version is compatible with this level of" - " Postgres.\n\tYou may need to run initdb to create" - " a new database system.\n\t%s", reason); + snprintf(errormsg, sizeof(errormsg), + "InitPostgres could not validate that the database" + " system version is compatible with this level of" + " Postgres.\n\tYou may need to run initdb to create" + " a new database system.\n\t%s", reason); } if (errormsg[0] != '\0') elog(FATAL, errormsg); @@ -185,7 +185,7 @@ VerifyMyDatabase() /* Failure reason returned by some function. NULL if no failure */ char *reason; int fd; - char errormsg[1000]; + char errormsg[MAXPGPATH+100]; name = DatabaseName; myPath = DatabasePath; @@ -195,26 +195,26 @@ VerifyMyDatabase() #else if ((fd = open(myPath, O_RDONLY | O_DIROPEN, 0)) == -1) #endif - sprintf(errormsg, - "Database '%s' does not exist." - "\n\tWe know this because the directory '%s' does not exist." - "\n\tYou can create a database with the SQL command" - " CREATE DATABASE.\n\tTo see what databases exist," - " look at the subdirectories of '%s/base/'.", - name, myPath, DataDir); + snprintf(errormsg, sizeof(errormsg), + "Database '%s' does not exist." + "\n\tWe know this because the directory '%s' does not exist." + "\n\tYou can create a database with the SQL command" + " CREATE DATABASE.\n\tTo see what databases exist," + " look at the subdirectories of '%s/base/'.", + name, myPath, DataDir); else { close(fd); ValidatePgVersion(myPath, &reason); if (reason != NULL) - sprintf(errormsg, - "InitPostgres could not validate that the database" - " version is compatible with this level of Postgres" - "\n\teven though the database system as a whole" - " appears to be at a compatible level." - "\n\tYou may need to recreate the database with SQL" - " commands DROP DATABASE and CREATE DATABASE." - "\n\t%s", reason); + snprintf(errormsg, sizeof(errormsg), + "InitPostgres could not validate that the database" + " version is compatible with this level of Postgres" + "\n\teven though the database system as a whole" + " appears to be at a compatible level." + "\n\tYou may need to recreate the database with SQL" + " commands DROP DATABASE and CREATE DATABASE." + "\n\t%s", reason); else { @@ -229,10 +229,10 @@ VerifyMyDatabase() rc = chdir(myPath); if (rc < 0) - sprintf(errormsg, - "InitPostgres unable to change " - "current directory to '%s', errno = %s (%d).", - myPath, strerror(errno), errno); + snprintf(errormsg, sizeof(errormsg), + "InitPostgres unable to change " + "current directory to '%s', errno = %s (%d).", + myPath, strerror(errno), errno); else errormsg[0] = '\0'; } diff --git a/src/backend/utils/misc/database.c b/src/backend/utils/misc/database.c index f5ff732b8f2..cda5cfbdab3 100644 --- a/src/backend/utils/misc/database.c +++ b/src/backend/utils/misc/database.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.30 1999/09/24 00:25:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.31 1999/10/25 03:07:52 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -30,7 +30,7 @@ GetDatabaseInfo(char *name, int4 *owner, char *path) { Oid dbowner, dbid; - char dbpath[MAXPGPATH + 1]; + char dbpath[MAXPGPATH]; text *dbtext; Relation dbrel; @@ -86,8 +86,7 @@ GetDatabaseInfo(char *name, int4 *owner, char *path) owner = palloc(sizeof(Oid)); *owner = dbowner; - path = palloc(strlen(dbpath) + 1); - strcpy(path, dbpath); + path = pstrdup(dbpath); /* doesn't do the right thing! */ return FALSE; } /* GetDatabaseInfo() */ @@ -97,46 +96,53 @@ GetDatabaseInfo(char *name, int4 *owner, char *path) char * ExpandDatabasePath(char *dbpath) { - char *path; + char buf[MAXPGPATH]; char *cp; - char buf[MAXPGPATH + 1]; + char *envvar; + int len; + + if (strlen(dbpath) >= MAXPGPATH) + return NULL; /* ain't gonna fit nohow */ /* leading path delimiter? then already absolute path */ if (*dbpath == SEP_CHAR) { #ifdef ALLOW_ABSOLUTE_DBPATHS cp = strrchr(dbpath, SEP_CHAR); - strncpy(buf, dbpath, (cp - dbpath)); - sprintf(&buf[cp - dbpath], "%cbase%c%s", SEP_CHAR, SEP_CHAR, (cp + 1)); + len = cp - dbpath; + strncpy(buf, dbpath, len); + snprintf(&buf[len], MAXPGPATH-len, "%cbase%c%s", + SEP_CHAR, SEP_CHAR, (cp + 1)); #else return NULL; #endif } /* path delimiter somewhere? then has leading environment variable */ - else if (strchr(dbpath, SEP_CHAR) != NULL) + else if ((cp = strchr(dbpath, SEP_CHAR)) != NULL) { - cp = strchr(dbpath, SEP_CHAR); - strncpy(buf, dbpath, (cp - dbpath)); - buf[cp - dbpath] = '\0'; - path = getenv(buf); + len = cp - dbpath; + strncpy(buf, dbpath, len); + buf[len] = '\0'; + envvar = getenv(buf); /* * problem getting environment variable? let calling routine * handle it */ - if (path == NULL) - return path; + if (envvar == NULL) + return envvar; - sprintf(buf, "%s%cbase%c%s", path, SEP_CHAR, SEP_CHAR, (cp + 1)); + snprintf(buf, sizeof(buf), "%s%cbase%c%s", + envvar, SEP_CHAR, SEP_CHAR, (cp + 1)); } - /* no path delimiter? then add the default path prefixes */ else - sprintf(buf, "%s%cbase%c%s", DataDir, SEP_CHAR, SEP_CHAR, dbpath); - - path = palloc(strlen(buf) + 1); - strcpy(path, buf); + { + /* no path delimiter? then add the default path prefix */ + snprintf(buf, sizeof(buf), "%s%cbase%c%s", + DataDir, SEP_CHAR, SEP_CHAR, dbpath); + } - return path; + return pstrdup(buf); } /* ExpandDatabasePath() */ |