Merge lp:~tyhicks/ecryptfs/cid1375979 into lp:ecryptfs

Proposed by Tyler Hicks on 2017-06-09
Status: Merged
Merged at revision: 894
Proposed branch: lp:~tyhicks/ecryptfs/cid1375979
Merge into: lp:ecryptfs
Diff against target: 12 lines (+0/-2)
1 file modified
src/libecryptfs/cmd_ln_parser.c (+0/-2)
To merge this branch: bzr merge lp:~tyhicks/ecryptfs/cid1375979
Reviewer Review Type Date Requested Status
Jason Xing (community) 2017-06-09 Approve on 2017-06-09
Review via email:

Description of the change

Remove unreachable code when parsing mount opt name value pairs

Revision 886 introduced a change to the mount option parsing code for
name-value pairs. A break was added to a loop once the first '=' is seen.
Before the break was added, it was possible that a '=' would be seen, then
memory allocated for the name portion of the string, then another '=' could be
seen and the previous name string be freed and then reallocated. However,
there's no longer a chance of needed to reallocate the name string so the
free() is not needed.

Discovered by Coverity (CID 1375979)

To post a comment you must log in.
Jason Xing (wlxing) wrote :

Thanks, Tyler.

You're right. We don't need to reallocate the memory for previous name string because we "break" the loop if we match the first "=". So the patch looks good for me :)

review: Approve
Tyler Hicks (tyhicks) wrote :

Thanks for the review!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/libecryptfs/cmd_ln_parser.c'
--- src/libecryptfs/cmd_ln_parser.c 2017-05-25 21:22:24 +0000
+++ src/libecryptfs/cmd_ln_parser.c 2017-06-09 15:33:38 +0000
@@ -288,8 +288,6 @@
288 j = 0;288 j = 0;
289 for (i = 0; i < st_len; i++)289 for (i = 0; i < st_len; i++)
290 if (sub_token[i] == '=') {290 if (sub_token[i] == '=') {
291 if (name)
292 free(name);
293 if (!(name = malloc(i + 1))) {291 if (!(name = malloc(i + 1))) {
294 rc = -ENOMEM;292 rc = -ENOMEM;
295 goto out;293 goto out;


People subscribed via source and target branches