[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Found some strange code
On Thu, 9 Oct 2003, Johan Danielsson wrote:
> Alexander Kjall <capitol@sigma.su.se> writes:
>
> > char *keytab = NULL;
> > struct ext_keytab_data data;
> >
> > args[0].value = &keytab;
>
> While strange, there is no problem with this; keytab is only used
> locally in that function, and args is not used anywhere else. I think
> the best solution is to make args local.
>
> /Johan
>
Well, args is used in the usage function, and num_args is dependent on it.
So the fix to make it local is sadly not that clean.
However, I included a patch to make args in ext.c local (diff against the
20031010 snapshot).
diff -Nur heimdal-20031010/kadmin/ext.c heimdal-20031010a/kadmin/ext.c
--- heimdal-20031010/kadmin/ext.c 2002-02-11 15:29:52.000000000 +0100
+++ heimdal-20031010a/kadmin/ext.c 2003-10-10 18:43:01.000000000 +0200
@@ -39,15 +39,17 @@
krb5_keytab keytab;
};
-static struct getargs args[] = {
- { "keytab", 'k', arg_string, NULL, "keytab to use" },
-};
-
-static int num_args = sizeof(args) / sizeof(args[0]);
-
static void
usage(void)
{
+ struct getargs args[] = {
+ { "keytab", 'k', arg_string, NULL, "keytab to use" },
+ };
+ /*WARNING if you change args or num_args don't forget to
+ change it in ext_keytab(int argc, char **argv) also (the
+ struct is repeted there.*/
+ int num_args = sizeof(args) / sizeof(args[0]);
+
arg_printusage(args, num_args, "ext", "principal...");
}
@@ -88,6 +90,13 @@
int optind = 0;
char *keytab = NULL;
struct ext_keytab_data data;
+ struct getargs args[] = {
+ { "keytab", 'k', arg_string, NULL, "keytab to use" },
+ };
+ /*WARNING if you change args or num_args don't forget to
+ change it in ext_keytab(int argc, char **argv) also (the
+ struct is repeted there.*/
+ int num_args = sizeof(args) / sizeof(args[0]);
args[0].value = &keytab;
if(getarg(args, num_args, argc, argv, &optind)){