Merge lp:~colin-king/ecryptfs/misc-fixes into lp:ecryptfs

Proposed by Colin Ian King
Status: Merged
Merged at revision: 777
Proposed branch: lp:~colin-king/ecryptfs/misc-fixes
Merge into: lp:ecryptfs
Diff against target: 234 lines (+41/-20)
9 files modified
src/libecryptfs/decision_graph.c (+2/-0)
src/libecryptfs/key_management.c (+0/-1)
src/libecryptfs/main.c (+2/-0)
src/libecryptfs/module_mgr.c (+1/-1)
src/utils/io.c (+2/-1)
src/utils/mount.ecryptfs_private.c (+12/-5)
tests/kernel/inotify/test.c (+16/-8)
tests/kernel/trunc-file/test.c (+5/-3)
tests/userspace/wrap-unwrap/test.c (+1/-1)
To merge this branch: bzr merge lp:~colin-king/ecryptfs/misc-fixes
Reviewer Review Type Date Requested Status
Tyler Hicks Approve
Review via email: mp+168057@code.launchpad.net

Description of the change

I've found a bunch of minor bugs which I've fixed up and I've given them a cursory check to see if they are OK and don't regress eCryptfs but I'd like somebody to eyeball them before merging if that's OK.

To post a comment you must log in.
Revision history for this message
Tyler Hicks (tyhicks) wrote :

Thanks, Colin! The only thing that caught my eye was the off_t to size_t changes. Since we're dealing with a file size, we should be using off_t rather than ssize_t (ssize_t wraps at 2GB on 32 bit machines). But, I see where other portions of that test use ssize_t so this change doesn't make us any worse off than what we already are at this point.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/libecryptfs/decision_graph.c'
--- src/libecryptfs/decision_graph.c 2009-05-29 14:03:56 +0000
+++ src/libecryptfs/decision_graph.c 2013-06-07 13:34:31 +0000
@@ -949,6 +949,7 @@
949 param_node->val))) {949 param_node->val))) {
950 syslog(LOG_ERR, "%s: Cannot find key_mod for param_node with "950 syslog(LOG_ERR, "%s: Cannot find key_mod for param_node with "
951 "val = [%s]\n", __FUNCTION__, param_node->val);951 "val = [%s]\n", __FUNCTION__, param_node->val);
952 free(subgraph_ctx);
952 goto out;953 goto out;
953 }954 }
954 (*foo) = (void *)subgraph_ctx;955 (*foo) = (void *)subgraph_ctx;
@@ -984,6 +985,7 @@
984 memset(val_node, 0, sizeof(struct val_node));985 memset(val_node, 0, sizeof(struct val_node));
985 if ((rc = asprintf((char **)&val_node->val, "%s", param_node->val))986 if ((rc = asprintf((char **)&val_node->val, "%s", param_node->val))
986 == -1) {987 == -1) {
988 free(val_node);
987 rc = -ENOMEM;989 rc = -ENOMEM;
988 goto out;990 goto out;
989 }991 }
990992
=== modified file 'src/libecryptfs/key_management.c'
--- src/libecryptfs/key_management.c 2012-10-03 19:58:04 +0000
+++ src/libecryptfs/key_management.c 2013-06-07 13:34:31 +0000
@@ -257,7 +257,6 @@
257 syslog(LOG_ERR, "Error attempting to open [%s] for reading\n",257 syslog(LOG_ERR, "Error attempting to open [%s] for reading\n",
258 src);258 src);
259 rc = -EIO;259 rc = -EIO;
260 close(fd);
261 goto out;260 goto out;
262 }261 }
263 if ((size = read(fd, decrypted_passphrase,262 if ((size = read(fd, decrypted_passphrase,
264263
=== modified file 'src/libecryptfs/main.c'
--- src/libecryptfs/main.c 2012-04-26 21:03:38 +0000
+++ src/libecryptfs/main.c 2013-06-07 13:34:31 +0000
@@ -116,10 +116,12 @@
116 } else {116 } else {
117 flockfile(fh);117 flockfile(fh);
118 if ((mnt = (char *)malloc(MAXPATHLEN+1)) == NULL) {118 if ((mnt = (char *)malloc(MAXPATHLEN+1)) == NULL) {
119 fclose(fh);
119 perror("malloc");120 perror("malloc");
120 return NULL;121 return NULL;
121 }122 }
122 if (fgets(mnt, MAXPATHLEN, fh) == NULL) {123 if (fgets(mnt, MAXPATHLEN, fh) == NULL) {
124 free(mnt);
123 mnt = mnt_default;125 mnt = mnt_default;
124 } else {126 } else {
125 /* Ensure that mnt doesn't contain newlines */127 /* Ensure that mnt doesn't contain newlines */
126128
=== modified file 'src/libecryptfs/module_mgr.c'
--- src/libecryptfs/module_mgr.c 2012-07-11 09:12:11 +0000
+++ src/libecryptfs/module_mgr.c 2013-06-07 13:34:31 +0000
@@ -578,7 +578,7 @@
578static int init_ecryptfs_cipher_param_node()578static int init_ecryptfs_cipher_param_node()
579{579{
580 struct cipher_descriptor *cd = cipher_descriptors;580 struct cipher_descriptor *cd = cipher_descriptors;
581 int rc;581 int rc = 0;
582582
583 while (cd && cd->name) {583 while (cd && cd->name) {
584 struct transition_node *tn;584 struct transition_node *tn;
585585
=== modified file 'src/utils/io.c'
--- src/utils/io.c 2009-05-29 14:03:56 +0000
+++ src/utils/io.c 2013-06-07 13:34:31 +0000
@@ -201,7 +201,7 @@
201 if (!confirmed_pass) {201 if (!confirmed_pass) {
202 rc = -ENOMEM;202 rc = -ENOMEM;
203 ecryptfs_syslog(LOG_ERR, "Failed to allocate memory\n");203 ecryptfs_syslog(LOG_ERR, "Failed to allocate memory\n");
204 goto out;204 goto ret;
205 }205 }
206 mlock(confirmed_pass, ECRYPTFS_MAX_PASSWORD_LENGTH);206 mlock(confirmed_pass, ECRYPTFS_MAX_PASSWORD_LENGTH);
207 printf("\n\tMount-wide passphrase: ");207 printf("\n\tMount-wide passphrase: ");
@@ -229,6 +229,7 @@
229out:229out:
230 memset(confirmed_pass, 0, ECRYPTFS_MAX_PASSWORD_LENGTH);230 memset(confirmed_pass, 0, ECRYPTFS_MAX_PASSWORD_LENGTH);
231 free(confirmed_pass);231 free(confirmed_pass);
232ret:
232 return rc;233 return rc;
233}234}
234235
235236
=== modified file 'src/utils/mount.ecryptfs_private.c'
--- src/utils/mount.ecryptfs_private.c 2012-12-04 20:00:49 +0000
+++ src/utils/mount.ecryptfs_private.c 2013-06-07 13:34:31 +0000
@@ -108,11 +108,13 @@
108 int i;108 int i;
109 char c;109 char c;
110 int len;110 int len;
111
112 if (u == NULL)
113 goto empty;
111 len = strlen(u);114 len = strlen(u);
112 if (u == NULL || len == 0) {115 if (len == 0)
113 fputs("Username is empty\n", stderr);116 goto empty;
114 return 1;117
115 }
116 for (i=0; i<len; i++) {118 for (i=0; i<len; i++) {
117 c = u[i];119 c = u[i];
118 if ( !(c>='a' && c<='z') && !(c>='A' && c<='Z') &&120 if ( !(c>='a' && c<='z') && !(c>='A' && c<='Z') &&
@@ -126,6 +128,9 @@
126 }128 }
127 }129 }
128 return 0;130 return 0;
131empty:
132 fputs("Username is empty\n", stderr);
133 return 1;
129}134}
130135
131char **fetch_sig(char *pw_dir, char *alias, int mounting) {136char **fetch_sig(char *pw_dir, char *alias, int mounting) {
@@ -390,8 +395,10 @@
390 (fstat(fd, &s)==0 && (S_ISREG(s.st_mode) && s.st_uid==uid))) {395 (fstat(fd, &s)==0 && (S_ISREG(s.st_mode) && s.st_uid==uid))) {
391 break;396 break;
392 } else {397 } else {
393 if (fd >= 0)398 if (fd >= 0) {
394 close(fd);399 close(fd);
400 fd = -1;
401 }
395 free(f);402 free(f);
396 if (asprintf(&f, "%s/%s-%s-%s-%d", TMP, FSTYPE, u,403 if (asprintf(&f, "%s/%s-%s-%s-%d", TMP, FSTYPE, u,
397 alias, i++) < 0) {404 alias, i++) < 0) {
398405
=== modified file 'tests/kernel/inotify/test.c'
--- tests/kernel/inotify/test.c 2012-01-31 13:55:17 +0000
+++ tests/kernel/inotify/test.c 2013-06-07 13:34:31 +0000
@@ -269,6 +269,7 @@
269{269{
270 int fd;270 int fd;
271 char buffer[1];271 char buffer[1];
272 int rc = 0;
272273
273 if ((fd = open(path, O_RDONLY)) < 0) {274 if ((fd = open(path, O_RDONLY)) < 0) {
274 fprintf(stderr, "Cannot open %s: %s\n", path, strerror(errno));275 fprintf(stderr, "Cannot open %s: %s\n", path, strerror(errno));
@@ -278,9 +279,12 @@
278 /* Just want to force an access */279 /* Just want to force an access */
279 if (read(fd, buffer, 1) < 0) {280 if (read(fd, buffer, 1) < 0) {
280 fprintf(stderr, "Cannot read %s: %s\n", path, strerror(errno));281 fprintf(stderr, "Cannot read %s: %s\n", path, strerror(errno));
281 return -1;282 rc = -1;
282 }283 }
283 return 0;284
285 close(fd);
286
287 return rc;
284}288}
285289
286int test_access_file(char *path)290int test_access_file(char *path)
@@ -301,23 +305,27 @@
301int test_modify_helper(char *path, void *dummy)305int test_modify_helper(char *path, void *dummy)
302{306{
303 int fd;307 int fd;
304 char buffer[1];308 char buffer[1] = { 0 };
309 int rc = 0;
305310
306 if (mk_file(path, 4096) < 0)311 if (mk_file(path, 4096) < 0)
307 return -1;312 return -1;
308313
309 if ((fd = open(path, O_RDWR)) < 0) {314 if ((fd = open(path, O_RDWR)) < 0) {
310 fprintf(stderr, "Cannot open %s: %s\n", path, strerror(errno));315 fprintf(stderr, "Cannot open %s: %s\n", path, strerror(errno));
311 return -1;316 rc = -1;
317 goto remove;
312 }318 }
313319
314 if (write(fd, buffer, 1) < 0) {320 if (write(fd, buffer, 1) < 0) {
315 fprintf(stderr, "Cannot read %s: %s\n", path, strerror(errno));321 fprintf(stderr, "Cannot write %s: %s\n", path, strerror(errno));
316 (void)unlink(path);322 rc = -1;
317 return -1;
318 }323 }
324
325 close(fd);
326remove:
319 (void)unlink(path);327 (void)unlink(path);
320 return 0;328 return rc;
321}329}
322330
323int test_modify_file(char *path)331int test_modify_file(char *path)
324332
=== modified file 'tests/kernel/trunc-file/test.c'
--- tests/kernel/trunc-file/test.c 2013-03-13 14:55:11 +0000
+++ tests/kernel/trunc-file/test.c 2013-06-07 13:34:31 +0000
@@ -84,10 +84,12 @@
8484
85 if (write_buff(fd, buff, n) < 0) {85 if (write_buff(fd, buff, n) < 0) {
86 close(fd);86 close(fd);
87 return TEST_FAILED;87 return -1;
88 }88 }
89 buflen -= n;89 buflen -= n;
90 }90 }
91
92 return 0;
91}93}
9294
93int test_read_random(char *filename, int fd, unsigned char *buff, ssize_t size)95int test_read_random(char *filename, int fd, unsigned char *buff, ssize_t size)
@@ -253,7 +255,7 @@
253255
254int main(int argc, char **argv)256int main(int argc, char **argv)
255{257{
256 off_t len = DEFAULT_SIZE;258 ssize_t len = DEFAULT_SIZE;
257 int i;259 int i;
258 int ret;260 int ret;
259261
@@ -278,5 +280,5 @@
278280
279 signal(SIGINT, sighandler);281 signal(SIGINT, sighandler);
280282
281 exit(test_exercise(argv[1], (ssize_t)len));283 exit(test_exercise(argv[1], len));
282}284}
283285
=== modified file 'tests/userspace/wrap-unwrap/test.c'
--- tests/userspace/wrap-unwrap/test.c 2012-11-02 23:20:18 +0000
+++ tests/userspace/wrap-unwrap/test.c 2013-06-07 13:34:31 +0000
@@ -102,7 +102,7 @@
102 if ((rc = ecryptfs_wrap_passphrase(path, "testwrappw", salt,102 if ((rc = ecryptfs_wrap_passphrase(path, "testwrappw", salt,
103 passphrase)) == 0) {103 passphrase)) == 0) {
104 fprintf(stderr, "ecryptfs_wrap_passphrase() returned rc = 0; "104 fprintf(stderr, "ecryptfs_wrap_passphrase() returned rc = 0; "
105 "expected error result instead\n", rc);105 "expected error result instead\n");
106 rc = 1;106 rc = 1;
107 goto out;107 goto out;
108 }108 }

Subscribers

People subscribed via source and target branches