A patch to fix the segment fault when no sub-command
diff mbox

Message ID CAK7bb8a7iGrJ6WPQqrCnWdXwwFKpd7E68CqLs3vFQ7noZOMF5A@mail.gmail.com
State New
Headers show

Commit Message

H Han Nov. 15, 2015, 1:25 a.m. UTC
Bug is reported on Redhat Bugzilla, id 1278543.
When use the invalid command like:
# cifscreds -u root
Will get a segment fault.
Add a argument check to avoid the segment fault when no sub-command, and
return with stderr 'Need command'.

the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/cifscreds.c b/cifscreds.c
index 5d84c3c..bb63369 100644
--- a/cifscreds.c
+++ b/cifscreds.c
@@ -488,6 +488,13 @@  int main(int argc, char **argv)
        }

        /* find the best fit command */
+
+        /* check if there is sub-command */
+        if (argv[optind] == NULL) {
+                fprintf(stderr, "Need command\n");
+                return EXIT_FAILURE;
+        }
+
        best = NULL;
        n = strnlen(argv[optind], MAX_COMMAND_SIZE);
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in