A few patches from Erik Hovland, turning strncpy() into safe_strncpy() and

removing some unnecessary code.
This commit is contained in:
Rob Landley 2006-06-25 00:34:52 +00:00
parent 641c3537c0
commit 768945b762
4 changed files with 6 additions and 12 deletions

View File

@ -42,12 +42,8 @@
#ifdef CONFIG_FEATURE_TAR_CREATE #ifdef CONFIG_FEATURE_TAR_CREATE
/* Tar file constants */ /* Tar file constants */
# define TAR_MAGIC "ustar" /* ustar and a null */
# define TAR_VERSION " " /* Be compatible with GNU tar format */
#define TAR_BLOCK_SIZE 512 #define TAR_BLOCK_SIZE 512
#define TAR_MAGIC_LEN 6
#define TAR_VERSION_LEN 2
/* POSIX tar Header Block, from POSIX 1003.1-1990 */ /* POSIX tar Header Block, from POSIX 1003.1-1990 */
#define NAME_SIZE 100 #define NAME_SIZE 100
@ -208,15 +204,14 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
memset(&header, 0, size); memset(&header, 0, size);
strncpy(header.name, header_name, sizeof(header.name)); safe_strncpy(header.name, header_name, sizeof(header.name));
putOctal(header.mode, sizeof(header.mode), statbuf->st_mode); putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
putOctal(header.uid, sizeof(header.uid), statbuf->st_uid); putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
putOctal(header.gid, sizeof(header.gid), statbuf->st_gid); putOctal(header.gid, sizeof(header.gid), statbuf->st_gid);
putOctal(header.size, sizeof(header.size), 0); /* Regular file size is handled later */ putOctal(header.size, sizeof(header.size), 0); /* Regular file size is handled later */
putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime); putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime);
strncpy(header.magic, TAR_MAGIC TAR_VERSION, strcpy(header.magic, "ustar ");
TAR_MAGIC_LEN + TAR_VERSION_LEN);
/* Enter the user and group names (default to root if it fails) */ /* Enter the user and group names (default to root if it fails) */
if (bb_getpwuid(header.uname, statbuf->st_uid, sizeof(header.uname)) == NULL) if (bb_getpwuid(header.uname, statbuf->st_uid, sizeof(header.uname)) == NULL)

View File

@ -699,13 +699,13 @@ int tune2fs_main(int argc, char **argv)
if (strlen(new_label) > sizeof(sb->s_volume_name)) if (strlen(new_label) > sizeof(sb->s_volume_name))
bb_error_msg("Warning: label too long, truncating\n"); bb_error_msg("Warning: label too long, truncating\n");
memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name)); memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
strncpy(sb->s_volume_name, new_label, safe_strncpy(sb->s_volume_name, new_label,
sizeof(sb->s_volume_name)); sizeof(sb->s_volume_name));
ext2fs_mark_super_dirty(fs); ext2fs_mark_super_dirty(fs);
} }
if (M_flag) { if (M_flag) {
memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted)); memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
strncpy(sb->s_last_mounted, new_last_mounted, safe_strncpy(sb->s_last_mounted, new_last_mounted,
sizeof(sb->s_last_mounted)); sizeof(sb->s_last_mounted));
ext2fs_mark_super_dirty(fs); ext2fs_mark_super_dirty(fs);
} }

View File

@ -1088,13 +1088,12 @@ static void Hit_Return(void)
//----- Synchronize the cursor to Dot -------------------------- //----- Synchronize the cursor to Dot --------------------------
static void sync_cursor(Byte * d, int *row, int *col) static void sync_cursor(Byte * d, int *row, int *col)
{ {
Byte *beg_cur, *end_cur; // begin and end of "d" line Byte *beg_cur; // begin and end of "d" line
Byte *beg_scr, *end_scr; // begin and end of screen Byte *beg_scr, *end_scr; // begin and end of screen
Byte *tp; Byte *tp;
int cnt, ro, co; int cnt, ro, co;
beg_cur = begin_line(d); // first char of cur line beg_cur = begin_line(d); // first char of cur line
end_cur = end_line(d); // last char of cur line
beg_scr = end_scr = screenbegin; // first char of screen beg_scr = end_scr = screenbegin; // first char of screen
end_scr = end_screen(); // last char of screen end_scr = end_screen(); // last char of screen

View File

@ -240,7 +240,7 @@ int zcip_main(int argc, char *argv[])
// initialize saddr // initialize saddr
memset(&saddr, 0, sizeof (saddr)); memset(&saddr, 0, sizeof (saddr));
strncpy(saddr.sa_data, intf, sizeof (saddr.sa_data)); safe_strncpy(saddr.sa_data, intf, sizeof (saddr.sa_data));
// open an ARP socket // open an ARP socket
if ((fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) < 0) { if ((fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) < 0) {