]> granicus.if.org Git - linux-pam/commitdiff
Relevant BUGIDs:
authorThorsten Kukuk <kukuk@thkukuk.de>
Wed, 25 Feb 2009 15:59:45 +0000 (15:59 +0000)
committerThorsten Kukuk <kukuk@thkukuk.de>
Wed, 25 Feb 2009 15:59:45 +0000 (15:59 +0000)
Purpose of commit: bugfix

Commit summary:
---------------

2009-02-25  Thorsten Kukuk  <kukuk@thkukuk.de>

        * libpam/pam_misc.c (_pam_StrTok): Use unsigned char
        instead of int. Reported by Marcus Granado.
        * tests/Makefile.am (TESTS): Add tst-pam_mkargv.
        * tests/tst-pam_mkargv.c (main): Test case for
        _pam_mkargv.

ChangeLog
libpam/pam_misc.c
tests/.cvsignore
tests/Makefile.am
tests/tst-pam_mkargv.c [new file with mode: 0644]

index faa2f07c065d8c1f08992d393db10b784d739f02..404507ca97a0ab9653c08239d97ddff6929bed7f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-02-25  Thorsten Kukuk  <kukuk@thkukuk.de>
+
+        * libpam/pam_misc.c (_pam_StrTok): Use unsigned char
+        instead of int. Reported by Marcus Granado.
+        * tests/Makefile.am (TESTS): Add tst-pam_mkargv.
+        * tests/tst-pam_mkargv.c (main): Test case for
+        _pam_mkargv.
+
 2008-12-09  Thorsten Kukuk  <kukuk@thkukuk.de>
 
        * release version 1.0.3
index 574a570e5da16c2bc88ead9191c7167ce929db43..b690fd3ef9f8e8e26091c26b946b3ae3a0895527 100644 (file)
@@ -59,10 +59,11 @@ char *_pam_StrTok(char *from, const char *format, char **next)
 
      /* initialize table */
      for (i=1; i<256; table[i++] = '\0');
-     for (i=0; format[i] ; table[(int)format[i++]] = 'y');
+     for (i=0; format[i] ;
+         table[(unsigned char)format[i++]] = 'y');
 
      /* look for first non-format char */
-     while (*from && table[(int)*from]) {
+     while (*from && table[(unsigned char)*from]) {
          ++from;
      }
 
@@ -92,7 +93,7 @@ char *_pam_StrTok(char *from, const char *format, char **next)
             remains */
      } else if (*from) {
         /* simply look for next blank char */
-        for (end=from; *end && !table[(int)*end]; ++end);
+        for (end=from; *end && !table[(unsigned char)*end]; ++end);
      } else {
         return (*next = NULL);                    /* no tokens left */
      }
index 8907f478a9806f4e909fd7d84a0232ac8f9af2b0..d8828fe6699ad65f8ee8df5eb89ba1c9a5f9be87 100644 (file)
@@ -18,3 +18,4 @@ tst-pam_set_data
 tst-pam_set_item
 tst-pam_setcred
 tst-pam_start
+tst-pam_mkargv
index de1594bdbb79ccdaec2113db982f81786e18b2e1..dfe745da9b3ca9fb32bfd68e5dd9f2177a1c4179 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2006 Thorsten Kukuk <kukuk@suse.de>
+# Copyright (c) 2006, 2009 Thorsten Kukuk <kukuk@suse.de>
 #
 
 AM_CFLAGS = -DLIBPAM_COMPILE -I$(top_srcdir)/libpam/include \
@@ -11,9 +11,9 @@ CLEANFILES = *~
 TESTS = tst-pam_start tst-pam_end tst-pam_fail_delay tst-pam_open_session \
        tst-pam_close_session tst-pam_acct_mgmt tst-pam_authenticate \
        tst-pam_chauthtok tst-pam_setcred tst-pam_get_item tst-pam_set_item \
-       tst-pam_getenvlist tst-pam_get_user tst-pam_set_data
+       tst-pam_getenvlist tst-pam_get_user tst-pam_set_data \
+       tst-pam_mkargv
 
 check_PROGRAMS = ${TESTS} tst-dlopen
 
 tst_dlopen_LDADD = -ldl
-
diff --git a/tests/tst-pam_mkargv.c b/tests/tst-pam_mkargv.c
new file mode 100644 (file)
index 0000000..11dcee9
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+   Copyright (C) Thorsten Kukuk <kukuk@suse.de> 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation in version 2 of the License.
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include "libpam/pam_misc.c"
+
+/* Simple program to see if _pam_mkargv() would succeed. */
+int main(void)
+{
+  char *argvstring = "user = XENDT\\userĪ± user=XENDT\\user1";
+  const char *argvresult[] = {"user", "=", "XENDT\\userĪ±",
+                             "user=XENDT\\user1"};
+  int myargc;
+  char **myargv;
+  int argvlen;
+  int i;
+
+  argvlen = _pam_mkargv(argvstring, &myargv, &myargc);
+
+#if 0
+  printf ("argvlen=%i, argc=%i", argvlen, myargc);
+  for (i = 0; i < myargc; i++) {
+    printf(", argv[%d]=%s", i, myargv[i]);
+  }
+  printf ("\n");
+#endif
+
+  if (argvlen != 333)
+    return 1;
+
+  if (myargc != 4)
+    return 1;
+
+  for (i = 0; i < 4; i++)
+    {
+      if (strcmp (myargv[i], argvresult[i]) != 0)
+       return 1;
+    }
+
+  return 0;
+}