]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Don't overwrite the last character of a line if it's not a newline. This would
authorRussell Bryant <russell@russellbryant.com>
Fri, 1 Feb 2008 17:23:47 +0000 (17:23 +0000)
committerRussell Bryant <russell@russellbryant.com>
Fri, 1 Feb 2008 17:23:47 +0000 (17:23 +0000)
happen if the last line in the file doesn't have a newline.
(pointed out by Qwell)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@101818 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_authenticate.c

index 5985993a819e3ef842366cf46fa1f26297858f59..c7a06182902063da35c7a8e3d9d76a0e2ce814d1 100644 (file)
@@ -169,7 +169,9 @@ static int auth_exec(struct ast_channel *chan, void *data)
                                        while (!feof(f)) {
                                                fgets(buf, sizeof(buf), f);
                                                if (!feof(f) && !ast_strlen_zero(buf)) {
-                                                       buf[strlen(buf) - 1] = '\0';
+                                                       size_t len = strlen(buf);
+                                                       if (buf[len] == '\n')
+                                                               buf[len] = '\0';
                                                        if (ast_test_flag(&flags,OPT_MULTIPLE)) {
                                                                md5secret = strchr(buf, ':');
                                                                if (md5secret == NULL)