Skip to contentSkip to conversation

Certificate Wizard 0.3b - code-related feedback

Openvpn-devel Charles Duffy 2 participants 3 messages Nov 12, 2004 – Nov 16, 2004 Kbuild

lore
Share & tools
lore
#0 lore raw

Vlada,

In updating my local Certificate Wizard fork to be based off 0.3b, I observed an issue introduced during your cleanup of my CopyOneFile function.

My original code:

    snprintf(buffer, MAXLINELEN, "Unable to copy \"%s\" to \"%s\" - error %d: %%s", source, target, errorCode);
    DisplayErrorToUser(errorCode, "Failure copying files", buffer);

Your replacement code:

    snprintf(buffer, MAXLINELEN, _("Unable to copy '%s' to '%s' - error %d", 0), source, target, errorCode);
    strcat(buffer, ": %%s");
    DisplayErrorToUser(errorCode, _("Failure copying files", 0), buffer);

These aren't functionally equivalent: The latter results in a literal '%s' being displayed to the user, whereas the former displays a textual description of the error message being substituted for the %s (which snprintf replaces %%s with) inside DisplayErrorToUser. Either the strcat should only append '%s' rather than '%%s', or '%%s' should be used in the snprintf (which is the approach I prefer -- but perhaps it interferes with the internationalization or somesuch?).

Additionally, I noticed a bug from my original code that you inherited:
in DisplayErrorToUser, the MsgBox call should take the description parameter (rather than a hardcoded string) as its argument.

The sum of non-site-specific changes I've made comes to the following:

misc.c 2004-11-12 19:38:27.000000000 -0600 renamed from misc.c 2004-11-09 10:02:44.000000000 -0600 +2 -3
diff -ru mycert-src-0.3b.orig/misc.c mycert-src-0.3b.recare/misc.c
@@ -232,7 +232,7 @@
                  0, NULL);
     
        strncpy(msgBuf, lpMsgBuf, MAXLINELEN);
-       MsgBox(_("Failure copying files", 0), MB_OK, fmt, msgBuf);
+       MsgBox(description, MB_OK, fmt, msgBuf);
        LocalFree(lpMsgBuf);
 }
 
@@ -242,8 +242,7 @@
                char buffer[MAXLINELEN+1];
                int errorCode = GetLastError();
 
-               snprintf(buffer, MAXLINELEN, _("Unable to copy '%s' to '%s' - error %d", 0), source, target, errorCode);
-               strcat(buffer, ": %%s");
+               snprintf(buffer, MAXLINELEN, _("Unable to copy '%s' to '%s' - error %d: %%s", 0), source, target, errorCode);
                DisplayErrorToUser(errorCode, _("Failure copying files", 0), buffer);
                return FALSE;
        }
mycert.ini 2004-11-12 19:51:45.000000000 -0600 renamed from mycert.ini 2004-11-09 10:02:44.000000000 -0600 +1 -1
@@ -299,7 +308,7 @@
 #Filename: %s=
 #(Cannot read the file.)=
 #Failure copying files=
-#Unable to copy '%s' to '%s' - error %d=
+#Unable to copy '%s' to '%s' - error %d: %%s=
 #Warning=
 
 

(For the record, since this is a public forum: while "recare" is mentioned in this message, my employer's name is Catalis Health -- we changed it recently because ECARE sued us. If you're an employee of ECARE, don't worry, we really are complying).

#1 lore raw

[Openvpn-devel] Certificate Wizard cross-compilation autodetection

The below patch to the My Certificate Wizard makefile attempts to determine whether a cross-compiler is available, and uses it if possible. I'd like to see it applied, such that both folks on win32 and *nix can use the same makefile w/o needing to twiddle it after checkout.

I haven't tested it on native win32; if the CROSSFOUND variable's determination doesn't work in your environment, I'd appreciate any suggestions wrt a better approach.

Thanks!

(Like my other non-private changes, this is available via GNU Arch; it can either be checked out or branched from my archive, or just browsed via the web address below once these changes get pulled by sourcecontrol.net).
http://archzoom.sourcecontrol.net/demo/[email protected].../mycert--fixes--0.3

Makefile +12 -7
@@ -15,14 +15,19 @@
 
 OBJS = mycert.o request.o misc.o mycert-res.o customize.o
 
+CROSSTGT := i586-mingw32msvc
+CROSSFOUND := $(shell which ${CROSSTGT}-gcc 2>/dev/null >/dev/null && echo YES || echo NO )
+
+ifeq (${CROSSFOUND},YES)
+  ## Cross-compiling
+  CC = ${CROSSTGT}-gcc
+  WINDRES = ${CROSSTGT}-windres
+else
+  ## For Windows using the mingw/msys environment
+  CC = gcc
+  WINDRES = windres
+endif
 
-## For Windows using the mingw/msys environment
-CC = gcc
-WINDRES = windres
-
-## Cross-compiling from Debian
-#CC = i586-mingw32msvc-gcc
-#WINDRES = i586-mingw32msvc-windres
 
 CFLAGS = -DREGULAR_EXPRESSIONS -O3 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin
 LDFLAGS = -mwindows -s -leay32
#2 lore raw
In reply to Charles Duffy

* Charles Duffy:

misc.c 2004-11-12 19:38:27.000000000 -0600 line 248

Quoted 11 lines
misc.c 2004-11-12 19:38:27.000000000 -0600 renamed from misc.c 2004-11-09 10:02:44.000000000 -0600 +1 -2
@@ -242,8 +242,7 @@
                char buffer[MAXLINELEN+1];
                int errorCode = GetLastError();
 
-               snprintf(buffer, MAXLINELEN, _("Unable to copy '%s' to '%s' - error %d", 0), source, target, errorCode);
-               strcat(buffer, ": %%s");
+               snprintf(buffer, MAXLINELEN, _("Unable to copy '%s' to '%s' - error %d: %%s", 0), source, target, errorCode);
                DisplayErrorToUser(errorCode, _("Failure copying files", 0), buffer);
                return FALSE;
        }

I believe that this is still wrong. The variables source and target might contain '%' characters, too.

In other places, the source code uses strncpy() in a lenient way. You might want to check these places and make sure that the buffer is always NUL-terminated.