Avoid unnecessary copying of a string in pg_restore.c
authorAndrew Dunstan <[email protected]>
Sun, 6 Apr 2025 13:21:09 +0000 (09:21 -0400)
committerAndrew Dunstan <[email protected]>
Sun, 6 Apr 2025 13:21:09 +0000 (09:21 -0400)
Coverity complained about a possible overrun in the copy, but there is
no actual need to copy the string at all.

src/bin/pg_dump/pg_restore.c

index c42e34b8a40b079adac9473903e130bf1f04038f..b3dbde0d04454f5b4918e415d8edde1cf54837b7 100644 (file)
@@ -1052,14 +1052,14 @@ get_dbname_oid_list_from_mfile(const char *dumpdirpath, SimpleOidStringList *dbn
    {
        Oid         db_oid = InvalidOid;
        char        db_oid_str[MAXPGPATH + 1] = "";
-       char        dbname[MAXPGPATH + 1] = "";
+       char       *dbname;
 
        /* Extract dboid. */
        sscanf(line, "%u", &db_oid);
        sscanf(line, "%20s", db_oid_str);
 
-       /* Now copy dbname. */
-       strcpy(dbname, line + strlen(db_oid_str) + 1);
+       /* dbname is the rest of the line */
+       dbname = line + strlen(db_oid_str) + 1;
 
        /* Remove \n from dbname. */
        dbname[strlen(dbname) - 1] = '\0';