From: Nathan Scott Date: Fri, 11 Jan 2002 04:01:45 +0000 (+0000) Subject: use snprintf instead of sprintf, to be sure, to be sure. X-Git-Tag: v2.0.0~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d9475a48bca8b35ce31001c1216fae56017c715;p=thirdparty%2Fxfsprogs-dev.git use snprintf instead of sprintf, to be sure, to be sure. --- diff --git a/bmap/xfs_bmap.c b/bmap/xfs_bmap.c index e7fb75163..88f1f45c5 100644 --- a/bmap/xfs_bmap.c +++ b/bmap/xfs_bmap.c @@ -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", diff --git a/db/check.c b/db/check.c index 0eaf9caa2..0aa0fb65c 100644 --- a/db/check.c +++ b/db/check.c @@ -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 b0413a76e..99886881e 100644 --- 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; diff --git a/db/print.c b/db/print.c index f4c747957..a17c9bc32 100644 --- a/db/print.c +++ b/db/print.c @@ -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, "]"); diff --git a/doc/CHANGES b/doc/CHANGES index 5a9cea20b..f4babb9a0 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -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 diff --git a/repair/Makefile b/repair/Makefile index b6d4feb71..43018632c 100644 --- a/repair/Makefile +++ b/repair/Makefile @@ -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) diff --git a/repair/avl.c b/repair/avl.c index a3f1758a1..d85101de0 100644 --- a/repair/avl.c +++ b/repair/avl.c @@ -34,10 +34,6 @@ #include -#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 */ diff --git a/repair/avl.h b/repair/avl.h index a6d53f5b9..2bf2ee0d2 100644 --- a/repair/avl.h +++ b/repair/avl.h @@ -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 diff --git a/repair/avl64.c b/repair/avl64.c index e165fdf75..edb66cba4 100644 --- a/repair/avl64.c +++ b/repair/avl64.c @@ -32,16 +32,6 @@ * * **************************************************************************/ -/* 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 #include #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 */ diff --git a/repair/avl64.h b/repair/avl64.h index 26ed977c3..d9cdc906b 100644 --- a/repair/avl64.h +++ b/repair/avl64.h @@ -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 diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index a4ff448d8..8d1655b63 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -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); diff --git a/repair/incore.h b/repair/incore.h index 22ffdea4f..525fd5619 100644 --- a/repair/incore.h +++ b/repair/incore.h @@ -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, diff --git a/repair/incore_ino.c b/repair/incore_ino.c index 4acce2a46..ba82ae3d9 100644 --- a/repair/incore_ino.c +++ b/repair/incore_ino.c @@ -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); diff --git a/repair/phase6.c b/repair/phase6.c index 0132c2b55..8847d36a1 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -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); diff --git a/rtcp/xfs_rtcp.c b/rtcp/xfs_rtcp.c index ebad94d5f..e31c75874 100644 --- a/rtcp/xfs_rtcp.c +++ b/rtcp/xfs_rtcp.c @@ -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)); } }