File: memory

package info (click to toggle)
dump 0.4b47-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,316 kB
  • sloc: ansic: 16,267; sh: 5,138; makefile: 161
file content (158 lines) | stat: -rw-r--r-- 4,645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Description: various memory-related patches
 clang-reported return value and space gotchas, dynamic treescan buffer alloc
Author: наб <nabijaczleweli@nabijaczleweli.xyz>
Bug-Debian: http://bugs.debian.org/995996
Bug-Debian: http://bugs.debian.org/1002836

--- a/restore/dirs.c
+++ b/restore/dirs.c
@@ -183,16 +183,15 @@ extractdirs(int genmode)
 	int fd;
 	char xattr[XATTR_MAXSIZE];
 	int xattr_found = 0;
+	_Bool is_tmp = command != 'r' && command != 'R';
 	dump_ino_t ino;
 
 	Vprintf(stdout, "Extract directories from tape\n");
-	(void) snprintf(dirfile, sizeof(dirfile), "%s/rstdir%ld", tmpdir,
-		(long)dumpdate);
-	if (command != 'r' && command != 'R') {
-		(void) strncat(dirfile, "-XXXXXX",
-			sizeof(dirfile) - strlen(dirfile));
+	(void) snprintf(dirfile, sizeof(dirfile), "%s/rstdir%ld%s", tmpdir,
+		(long)dumpdate, is_tmp ? "-XXXXXX" : "");
+	if (is_tmp)
 		fd = mkstemp(dirfile);
-	} else
+	else
 		fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
 	if (fd == -1 || (df = fdopen(fd, "w")) == NULL) {
 		if (fd != -1)
@@ -200,12 +199,10 @@ extractdirs(int genmode)
 		err(1, "cannot create directory temporary %s", dirfile);
 	}
 	if (genmode != 0) {
-		(void) snprintf(modefile, sizeof(modefile), "%s/rstmode%ld", tmpdir, (long)dumpdate);
-		if (command != 'r' && command != 'R') {
-			(void) strncat(modefile, "-XXXXXX",
-				sizeof(modefile) - strlen(modefile));
+		(void) snprintf(modefile, sizeof(modefile), "%s/rstmode%ld%s", tmpdir, (long)dumpdate, is_tmp ? "-XXXXXX" : "");
+		if (is_tmp)
 			fd = mkstemp(modefile);
-		} else
+		else
 			fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
 		if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) {
 			if (fd != -1)
@@ -287,9 +284,8 @@ treescan(char *pname, dump_ino_t ino, lo
 {
 	struct inotab *itp;
 	struct direct *dp;
-	int namelen;
 	off_t bpt;
-	char locname[MAXPATHLEN + 1];
+	char *locname;
 
 	itp = inotablookup(ino);
 	if (itp == NULL) {
@@ -308,9 +304,6 @@ treescan(char *pname, dump_ino_t ino, lo
 	 * begin search through the directory
 	 * skipping over "." and ".."
 	 */
-	namelen = snprintf(locname, sizeof(locname), "%s/", pname);
-	if (namelen >= (int)sizeof(locname))
-		namelen = sizeof(locname) - 1;
 	rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
 	dp = rst_readdir(dirp); /* "." */
 	if (dp != NULL && strcmp(dp->d_name, ".") == 0)
@@ -328,15 +321,13 @@ treescan(char *pname, dump_ino_t ino, lo
 	 * a zero inode signals end of directory
 	 */
 	while (dp != NULL) {
-		locname[namelen] = '\0';
-		if (namelen + dp->d_namlen >= (int)sizeof(locname)) {
-			fprintf(stderr, "%s%s: name exceeds %ld char\n",
-				locname, dp->d_name, (long)sizeof(locname) - 1);
-		} else {
-			(void) strncat(locname, dp->d_name, (int)dp->d_namlen);
-			treescan(locname, dp->d_ino, todo);
-			rst_seekdir(dirp, bpt, itp->t_seekpt);
+		if (asprintf(&locname, "%s/%.*s", pname, (int)dp->d_namlen, dp->d_name) == -1) {
+			panic("Error: %s\n", strerror(errno));
+			abort();
 		}
+		treescan(locname, dp->d_ino, todo);
+		free(locname);
+		rst_seekdir(dirp, bpt, itp->t_seekpt);
 		dp = rst_readdir(dirp);
 		bpt = rst_telldir(dirp);
 	}
--- a/common/indexer_test.c
+++ b/common/indexer_test.c
@@ -105,7 +105,7 @@ mkchecksum(union u_spcl *tmpspcl)
 /*
  *
  */
-int
+void
 dump_inode(Indexer *indexer, struct stat *buf)
 {
 	struct dinode dinode;
@@ -176,12 +176,13 @@ dump_walk(Indexer *indexer, const char *
 		}
 	}
 	closedir(dirp);
+  return 0;
 }
 
 /*
  *
  */
-int
+void
 test_indexer(Indexer *indexer, const char *filename, const char *path)
 {
 	struct direct dp;
--- a/restore/xattr.c
+++ b/restore/xattr.c
@@ -314,7 +314,7 @@ fail:
 static int
 xattr_cb_list(char *name, char *value, int valuelen, int isSELinux, void *private)
 {
-	isSELinux;
+	(void) isSELinux;
 	value[valuelen] = '\0';
 	printf("EA: %s:%s\n", name, value);
 
@@ -330,7 +330,7 @@ xattr_cb_set(char *name, char *value, in
 	if (Nflag)
 		return GOOD;
 
-	isSELinux;
+	(void) isSELinux;
 #ifdef TRANSSELINUX			/*GAN6May06 SELinux MLS */
 	if (isSELinux)
 		err = lsetfilecon(path, value);
@@ -353,11 +353,11 @@ xattr_cb_compare(char *name, char *value
 	char valuef[XATTR_MAXSIZE];
 	int valuesz;
 
-	isSELinux;
+	(void) isSELinux;
 #ifdef TRANSSELINUX			/*GAN6May06 SELinux MLS */
 	if (isSELinux)
 	{
-		security_context_t con = NULL;
+		char *con = NULL;
 
 		if (lgetfilecon(path, &con) < 0) {
 			warn("%s: EA compare lgetfilecon failed\n", path);
@@ -513,7 +513,7 @@ xattr_walk(char *buffer, int (*xattr_cb)
 			convertcon = 0;	/*GAN24May06 only for selinux */
 
 		if (convertcon) {
-			security_context_t con = NULL;
+			char *con = NULL;
 			int err;
 
 			if (!transselinuxarg)