]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
use snprintf instead of sprintf, to be sure, to be sure.
authorNathan Scott <nathans@sgi.com>
Fri, 11 Jan 2002 04:01:45 +0000 (04:01 +0000)
committerNathan Scott <nathans@sgi.com>
Fri, 11 Jan 2002 04:01:45 +0000 (04:01 +0000)
15 files changed:
bmap/xfs_bmap.c
db/check.c
db/io.c
db/print.c
doc/CHANGES
repair/Makefile
repair/avl.c
repair/avl.h
repair/avl64.c
repair/avl64.h
repair/dino_chunks.c
repair/incore.h
repair/incore_ino.c
repair/phase6.c
rtcp/xfs_rtcp.c

index e7fb75163be121c2c8972278e0356b37106d8ebf..88f1f45c5e8f193552d96606f4650617c5bfb343 100644 (file)
@@ -333,7 +333,7 @@ dofile(char *fname)
                 * needed for all columns.
                 */
                for (i = 0; i < map->bmv_entries; i++) {
-                       sprintf(rbuf, "[%lld..%lld]:", 
+                       snprintf(rbuf, sizeof(rbuf), "[%lld..%lld]:", 
                                (long long) map[i + 1].bmv_offset,
                                (long long)(map[i + 1].bmv_offset +
                                map[i + 1].bmv_length - 1LL));
@@ -342,13 +342,13 @@ dofile(char *fname)
                                tot_w = max(tot_w, 
                                        numlen(map[i+1].bmv_length));
                        } else {
-                               sprintf(bbuf, "%lld..%lld", 
+                               snprintf(bbuf, sizeof(bbuf), "%lld..%lld", 
                                        (long long) map[i + 1].bmv_block,
                                        (long long)(map[i + 1].bmv_block +
                                                map[i + 1].bmv_length - 1LL));
                                agno = map[i + 1].bmv_block / bbperag;
                                agoff = map[i + 1].bmv_block - (agno * bbperag);
-                               sprintf(abuf, "(%lld..%lld)", 
+                               snprintf(abuf, sizeof(abuf), "(%lld..%lld)", 
                                        (long long)agoff,  (long long)
                                        (agoff + map[i + 1].bmv_length - 1LL));
                                foff_w = max(foff_w, strlen(rbuf)); 
@@ -367,7 +367,7 @@ dofile(char *fname)
                        aoff_w, "AG-OFFSET", 
                        tot_w, "TOTAL");
                for (i = 0; i < map->bmv_entries; i++) {
-                       sprintf(rbuf, "[%lld..%lld]:", 
+                       snprintf(rbuf, sizeof(rbuf), "[%lld..%lld]:", 
                                (long long) map[i + 1].bmv_offset,
                                (long long)(map[i + 1].bmv_offset +
                                map[i + 1].bmv_length - 1LL));
@@ -380,13 +380,13 @@ dofile(char *fname)
                                        aoff_w, "", 
                                        tot_w, (long long)map[i+1].bmv_length);
                        } else {
-                               sprintf(bbuf, "%lld..%lld", 
+                               snprintf(bbuf, sizeof(bbuf), "%lld..%lld", 
                                        (long long) map[i + 1].bmv_block,
                                        (long long)(map[i + 1].bmv_block +
                                                map[i + 1].bmv_length - 1LL));
                                agno = map[i + 1].bmv_block / bbperag;
                                agoff = map[i + 1].bmv_block - (agno * bbperag);
-                               sprintf(abuf, "(%lld..%lld)", 
+                               snprintf(abuf, sizeof(abuf), "(%lld..%lld)", 
                                        (long long)agoff,  (long long)
                                        (agoff + map[i + 1].bmv_length - 1LL));
                                printf("%4d: %-*s %-*s %*d %-*s %*lld\n", 
index 0eaf9caa2acffeab98b0622e0b1f36bb878ef413..0aa0fb65c91af1a3f01e5f43f8bfbf021b25c5a3 100644 (file)
@@ -1898,7 +1898,7 @@ prepend_path(
 
        len = (int)(strlen(oldpath) + strlen(parent) + 2);
        path = xmalloc(len);
-       sprintf(path, "%s/%s", parent, oldpath);
+       snprintf(path, len, "%s/%s", parent, oldpath);
        return path;
 }
 
diff --git a/db/io.c b/db/io.c
index b0413a76eca1a1b63fddbbc558e4420ad1b7840b..99886881ebda9dcd66f638a5bfc76f03fb67d855 100644 (file)
--- a/db/io.c
+++ b/db/io.c
@@ -618,8 +618,8 @@ stack_f(
        int     i;
        char    tagbuf[8];
 
-       for (i = iocur_sp; i >= 0; i--) {
-               sprintf(tagbuf, "%d: ", i);
+       for (i = iocur_sp; i > 0; i--) {
+               snprintf(tagbuf, sizeof(tagbuf), "%d: ", i);
                print_iocur(tagbuf, &iocur_base[i]);
        }
        return 0;
index f4c74795742985af0d9cc6b78270c315cdf17401..a17c9bc322b8ff3e72b5d155e9b1411ad6ec96df 100644 (file)
@@ -131,11 +131,11 @@ print_flist_1(
                        add_strvec(&pfx, fl->name);
                if (fl->flags & FL_OKLOW) {
                        add_strvec(&pfx, "[");
-                       sprintf(buf, "%d", fl->low);
+                       snprintf(buf, sizeof(buf), "%d", fl->low);
                        add_strvec(&pfx, buf);
                        if (fl->low != fl->high) {
                                add_strvec(&pfx, "-");
-                               sprintf(buf, "%d", fl->high);
+                               snprintf(buf, sizeof(buf), "%d", fl->high);
                                add_strvec(&pfx, buf);
                        }
                        add_strvec(&pfx, "]");
index 5a9cea20b6afc4efd20a9531735d02ff7386c84f..f4babb9a04f0710f49b19938cd7022d9c664b06e 100644 (file)
@@ -1,3 +1,8 @@
+[current]
+       - xfs_repair fix to prevent double insertion into the
+         uncertain_inode AVL trees
+       - use snprintf instead of sprintf
+
 xfsprogs-1.3.16 (17 December 2001)
        - added text dump type to xfs_db (mkp)
        - removed use of a temporary file in xfs_db when processing
index b6d4feb719ba4eedc306143ac0e0b1e170088064..43018632c0f24ea659a579582adccf714e7b0f26 100644 (file)
@@ -66,7 +66,7 @@ include $(BUILDRULES)
 # -DXR_BLD_ADD_EXTENT  track phase 5 block extent creation
 # -DXR_BCKPTR_DBG      parent list debugging info
 #
-CFLAGS += -DAVL_USER_MODE -DAVL_FUTURE_ENHANCEMENTS
+#CFLAGS += ...
 
 install: default
        $(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
index a3f1758a1c291af3efca7fae13d8c1507d1be46a..d85101de005d750d3a76a5678bf871e51dfe94a3 100644 (file)
 
 #include <libxfs.h>
 
-#if defined(STAND_ALONE_DEBUG) || defined(AVL_USER_MODE_DEBUG)
-#define AVL_DEBUG
-#endif
-
 #include "avl.h"
 
 #define CERT   ASSERT
@@ -1056,19 +1052,10 @@ avl_insert(
 
        if ((np = avl_insert_find_growth(tree, start, end, &growth)) == NULL) {
                if (start != end)  { /* non-zero length range */
-#ifdef AVL_USER_MODE
-                       printf(
-                       "avl_insert: Warning! duplicate range [0x%llx,0x%lx)\n",
-                               (unsigned long long)start, (unsigned long)end);
-#else
-                       /*
-                        * lockmetering tree can't afford printfs here.
-                        */
-                       if (!(tree->avl_flags & AVLF_DUPLICITY))
-                       cmn_err(CE_CONT,
-                       "!avl_insert: Warning! duplicate range [0x%x,0x%x)\n",
-                       start, end);
-#endif
+                       fprintf(stderr,
+                       "avl_insert: Warning! duplicate range [%llu,%llu]\n",
+                               (unsigned long long)start,
+                               (unsigned long long)end);
                }
                return(NULL);
        }
@@ -1151,12 +1138,6 @@ avl_firstino(register avlnode_t *root)
        return np;
 }
 
-#ifdef AVL_USER_MODE
-/*
- * leave this as a user-mode only routine until someone actually
- * needs it in the kernel
- */
-
 /*
  *     Returns last in order node
  */
@@ -1172,7 +1153,6 @@ avl_lastino(register avlnode_t *root)
                np = np->avl_forw;
        return np;
 }
-#endif
 
 void
 avl_init_tree(avltree_desc_t *tree, avlops_t *ops)
@@ -1409,7 +1389,6 @@ avl_findadjacent(
 }
 
 
-#ifdef AVL_FUTURE_ENHANCEMENTS
 /*
  *     avl_findranges:
  *
@@ -1461,5 +1440,3 @@ avl_findranges(
        *endp = avl_findadjacent(tree, (end-1), AVL_PRECEED);
        ASSERT(*endp);
 }
-
-#endif /* AVL_FUTURE_ENHANCEMENTS */
index a6d53f5b91037ca3912815a088805a6edfd43bd0..2bf2ee0d2108aa4e4f54ac7b283357191624ad5c 100644 (file)
@@ -124,7 +124,6 @@ avl_findadjacent(
        __psunsigned_t value,
        int             dir);
 
-#ifdef AVL_FUTURE_ENHANCEMENTS
 void
 avl_findranges(
        register avltree_desc_t *tree,
@@ -132,7 +131,6 @@ avl_findranges(
        register __psunsigned_t end,
        avlnode_t               **startp,
        avlnode_t               **endp);
-#endif
 
 #define AVL_PRECEED    0x1
 #define AVL_SUCCEED    0x2
index e165fdf75e621ac396504238600d96ff978cae17..edb66cba4db8976730f77eaf711c4cdd1fa15f44 100644 (file)
  *                                                                       *
  **************************************************************************/
 
-/* to allow use by user-level utilities */
-
-#ifdef STAND_ALONE_DEBUG
-#define AVL_USER_MODE
-#endif
-
-#if defined(STAND_ALONE_DEBUG) || defined(AVL_USER_MODE_DEBUG)
-#define AVL_DEBUG
-#endif
-
 #include <stdio.h>
 #include <libxfs.h>
 #include "avl64.h"
@@ -1054,14 +1044,10 @@ avl64_insert(
        if ((np = avl64_insert_find_growth(tree, start, end, &growth))
                        == NULL) {
                if (start != end)  { /* non-zero length range */
-#ifdef AVL_USER_MODE
-               printf("avl_insert: Warning! duplicate range [0x%llx,0x%llx)\n",
-                       (unsigned long long)start, (unsigned long long)end);
-#else
-                       cmn_err(CE_CONT,
-               "!avl_insert: Warning! duplicate range [0x%llx,0x%llx)\n",
-                               start, end);
-#endif
+                       fprintf(stderr,
+                       "avl_insert: Warning! duplicate range [%llu,%llu]\n",
+                               (unsigned long long)start,
+                               (unsigned long long)end);
                }
                return(NULL);
        }
@@ -1144,12 +1130,6 @@ avl64_firstino(register avl64node_t *root)
        return np;
 }
 
-#ifdef AVL_USER_MODE
-/*
- * leave this as a user-mode only routine until someone actually
- * needs it in the kernel
- */
-
 /*
  *     Returns last in order node
  */
@@ -1165,7 +1145,6 @@ avl64_lastino(register avl64node_t *root)
                np = np->avl_forw;
        return np;
 }
-#endif
 
 void
 avl64_init_tree(avl64tree_desc_t *tree, avl64ops_t *ops)
@@ -1402,7 +1381,6 @@ avl64_findadjacent(
 }
 
 
-#ifdef AVL_FUTURE_ENHANCEMENTS
 /*
  *     avl_findranges:
  *
@@ -1454,5 +1432,3 @@ avl64_findranges(
        *endp = avl64_findadjacent(tree, (end-1), AVL_PRECEED);
        ASSERT(*endp);
 }
-
-#endif /* AVL_FUTURE_ENHANCEMENTS */
index 26ed977c392a58d0854cb5560f6914e2032c38e0..d9cdc906b6b9969ff27c64c7c8a7dc17756fb147 100644 (file)
@@ -126,7 +126,6 @@ avl64_findadjacent(
        __uint64_t      value,
        int             dir);
 
-#ifdef AVL_FUTURE_ENHANCEMENTS
 void
 avl64_findranges(
        register avl64tree_desc_t *tree,
@@ -134,7 +133,6 @@ avl64_findranges(
        register __uint64_t     end,
        avl64node_t             **startp,
        avl64node_t             **endp);
-#endif
 
 /*
  * avoid complaints about multiple def's since these are only used by
index a4ff448d8ceb82cdc20a55a5d21264865e5696fd..8d1655b639de68e073506b44d7f0e2e065eb2d27 100644 (file)
@@ -248,10 +248,12 @@ verify_inode_chunk(xfs_mount_t            *mp,
                        return(0);
 
                /*
-                * ok, put the record into the tree.  we know that it's
-                * not already there since the inode is guaranteed
-                * not to be in the tree.
+                * ok, put the record into the tree, if no conflict.
                 */
+               if (find_uncertain_inode_rec(agno,
+                               XFS_OFFBNO_TO_AGINO(mp, start_agbno, 0)))
+                       return(0);
+
                start_agino = XFS_OFFBNO_TO_AGINO(mp, start_agbno, 0);
                *start_ino = XFS_AGINO_TO_INO(mp, agno, start_agino);
 
index 22ffdea4f05a0dd77cc3dc46406387b49e3687ed..525fd561964c9517a6b8365aa1105f89b1c2151c 100644 (file)
@@ -383,6 +383,8 @@ void                print_uncertain_inode_list(xfs_agnumber_t agno);
  * separate trees for uncertain inodes (they may not exist).
  */
 ino_tree_node_t                *findfirst_uncertain_inode_rec(xfs_agnumber_t agno);
+ino_tree_node_t                *find_uncertain_inode_rec(xfs_agnumber_t agno,
+                                               xfs_agino_t ino);
 void                   add_inode_uncertain(xfs_mount_t *mp,
                                                xfs_ino_t ino, int free);
 void                   add_aginode_uncertain(xfs_agnumber_t agno,
index 4acce2a46bb05d6b763700734bbf870be80af19f..ba82ae3d9ba30379e2b321eec158a6c2e5a46b73 100644 (file)
@@ -202,7 +202,8 @@ add_aginode_uncertain(xfs_agnumber_t agno, xfs_agino_t ino, int free)
 
                if (avl_insert(inode_uncertain_tree_ptrs[agno],
                                (avlnode_t *) ino_rec) == NULL)  {
-                       do_error("xfs_repair:  duplicate inode range\n");
+                       do_error("xfs_repair: add_aginode_uncertain - "
+                               "duplicate inode range\n");
                }
        }
 
@@ -253,6 +254,13 @@ findfirst_uncertain_inode_rec(xfs_agnumber_t agno)
                inode_uncertain_tree_ptrs[agno]->avl_firstino);
 }
 
+ino_tree_node_t *
+find_uncertain_inode_rec(xfs_agnumber_t agno, xfs_agino_t ino)
+{
+       return((ino_tree_node_t *)
+               avl_findrange(inode_uncertain_tree_ptrs[agno], ino));
+}
+
 void
 clear_uncertain_ino_cache(xfs_agnumber_t agno)
 {
@@ -296,7 +304,7 @@ add_inode(xfs_agnumber_t agno, xfs_agino_t ino)
 
        if (avl_insert(inode_tree_ptrs[agno],
                        (avlnode_t *) ino_rec) == NULL)  {
-               do_error("xfs_repair:  duplicate inode range\n");
+               do_warn("xfs_repair: add_inode - duplicate inode range\n");
        }
 
        return(ino_rec);
index 0132c2b55ac1f98d611c50cf66104154f8bfc154..8847d36a1160495e49649ab0b1e4f40cba6d4765 100644 (file)
@@ -822,7 +822,7 @@ mv_orphanage(xfs_mount_t    *mp,
        char            fname[MAXPATHLEN + 1];
        int             nres;
 
-       sprintf(fname, "%llu", (unsigned long long)ino);
+       snprintf(fname, sizeof(fname), "%llu", (unsigned long long)ino);
 
        if ((err = libxfs_iget(mp, NULL, dir_ino, 0, &dir_ino_p, 0)))
                do_error("%d - couldn't iget orphanage inode\n", err);
index ebad94d5fc22592953a3ccb21068b76765580e24..e31c7587494b28cf23d03ce5b226067290e85884 100644 (file)
@@ -157,14 +157,14 @@ rtcp( char *source, char *target, int fextsize)
        /*
         * check for a realtime partition
         */
-       sprintf(tbuf,"%s",target);
+       snprintf(tbuf, sizeof(tbuf), "%s", target);
        if ( stat(target, &s2) ) {
                if (!S_ISDIR(s2.st_mode)) {
                        /* take out target file name */
                        if ((ptr = strrchr(tbuf, '/')) != NULL)
                                *ptr = '\0';
                        else
-                               sprintf(tbuf, ".");
+                               snprintf(tbuf, sizeof(tbuf), ".");
                } 
        }
 
@@ -177,10 +177,11 @@ rtcp( char *source, char *target, int fextsize)
        /*
         * check if target is a directory
         */
-       sprintf(tbuf,"%s",target);
+       snprintf(tbuf, sizeof(tbuf), "%s", target);
        if ( !stat(target, &s2) ) {
                if (S_ISDIR(s2.st_mode)) {
-                       sprintf(tbuf,"%s/%s",target, basename(source));
+                       snprintf(tbuf, sizeof(tbuf), "%s/%s", target,
+                               basename(source));
                } 
        }