Skip to content

Commit f7e1e01

Browse files
committed
Remove workarounds for non-ANSI-C compatible compilers (Part 1)
1 parent f5c5de6 commit f7e1e01

File tree

15 files changed

+65
-603
lines changed

15 files changed

+65
-603
lines changed

configure

Lines changed: 9 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -551,193 +551,26 @@ fi
551551

552552
echo >> configure.log
553553

554-
# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
555-
# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
556-
# return value. The most secure result is vsnprintf() with a return value. snprintf() with a
557-
# return value is secure as well, but then gzprintf() will be limited to 20 arguments.
554+
# Check for ANSI C compliant compiler
558555
cat > $test.c <<EOF
559556
#include <stdio.h>
560557
#include <stdarg.h>
561558
#include "zconf.h"
562559
int main()
563560
{
564-
#ifndef STDC
565-
choke me
566-
#endif
561+
#ifdef STDC
567562
return 0;
563+
#endif
564+
return 1;
568565
}
569566
EOF
570567
if try $CC -c $CFLAGS $test.c; then
571-
echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
572-
573-
echo >> configure.log
574-
cat > $test.c <<EOF
575-
#include <stdio.h>
576-
#include <stdarg.h>
577-
int mytest(const char *fmt, ...)
578-
{
579-
char buf[20];
580-
va_list ap;
581-
va_start(ap, fmt);
582-
vsnprintf(buf, sizeof(buf), fmt, ap);
583-
va_end(ap);
584-
return 0;
585-
}
586-
int main()
587-
{
588-
return (mytest("Hello%d\n", 1));
589-
}
590-
EOF
591-
if try $CC $CFLAGS -o $test $test.c; then
592-
echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
593-
594-
echo >> configure.log
595-
cat >$test.c <<EOF
596-
#include <stdio.h>
597-
#include <stdarg.h>
598-
int mytest(const char *fmt, ...)
599-
{
600-
int n;
601-
char buf[20];
602-
va_list ap;
603-
va_start(ap, fmt);
604-
n = vsnprintf(buf, sizeof(buf), fmt, ap);
605-
va_end(ap);
606-
return n;
607-
}
608-
int main()
609-
{
610-
return (mytest("Hello%d\n", 1));
611-
}
612-
EOF
613-
614-
if try $CC -c $CFLAGS $test.c; then
615-
echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
616-
else
617-
CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
618-
SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
619-
echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
620-
echo " WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
621-
echo " can build but will be open to possible string-format security" | tee -a configure.log
622-
echo " vulnerabilities." | tee -a configure.log
623-
fi
624-
else
625-
CFLAGS="$CFLAGS -DNO_vsnprintf"
626-
SFLAGS="$SFLAGS -DNO_vsnprintf"
627-
echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
628-
echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
629-
echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log
630-
echo " vulnerabilities." | tee -a configure.log
631-
632-
echo >> configure.log
633-
cat >$test.c <<EOF
634-
#include <stdio.h>
635-
#include <stdarg.h>
636-
int mytest(const char *fmt, ...)
637-
{
638-
int n;
639-
char buf[20];
640-
va_list ap;
641-
va_start(ap, fmt);
642-
n = vsprintf(buf, fmt, ap);
643-
va_end(ap);
644-
return n;
645-
}
646-
int main()
647-
{
648-
return (mytest("Hello%d\n", 1));
649-
}
650-
EOF
651-
652-
if try $CC -c $CFLAGS $test.c; then
653-
echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
654-
else
655-
CFLAGS="$CFLAGS -DHAS_vsprintf_void"
656-
SFLAGS="$SFLAGS -DHAS_vsprintf_void"
657-
echo "Checking for return value of vsprintf()... No." | tee -a configure.log
658-
echo " WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
659-
echo " can build but will be open to possible string-format security" | tee -a configure.log
660-
echo " vulnerabilities." | tee -a configure.log
661-
fi
662-
fi
568+
echo "Checking for ANSI C compliant compiler... Yes." | tee -a configure.log
569+
:
663570
else
664-
echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
665-
666-
echo >> configure.log
667-
cat >$test.c <<EOF
668-
#include <stdio.h>
669-
int mytest()
670-
{
671-
char buf[20];
672-
snprintf(buf, sizeof(buf), "%s", "foo");
673-
return 0;
674-
}
675-
int main()
676-
{
677-
return (mytest());
678-
}
679-
EOF
680-
681-
if try $CC $CFLAGS -o $test $test.c; then
682-
echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
683-
684-
echo >> configure.log
685-
cat >$test.c <<EOF
686-
#include <stdio.h>
687-
int mytest()
688-
{
689-
char buf[20];
690-
return snprintf(buf, sizeof(buf), "%s", "foo");
691-
}
692-
int main()
693-
{
694-
return (mytest());
695-
}
696-
EOF
697-
698-
if try $CC -c $CFLAGS $test.c; then
699-
echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
700-
else
701-
CFLAGS="$CFLAGS -DHAS_snprintf_void"
702-
SFLAGS="$SFLAGS -DHAS_snprintf_void"
703-
echo "Checking for return value of snprintf()... No." | tee -a configure.log
704-
echo " WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
705-
echo " can build but will be open to possible string-format security" | tee -a configure.log
706-
echo " vulnerabilities." | tee -a configure.log
707-
fi
708-
else
709-
CFLAGS="$CFLAGS -DNO_snprintf"
710-
SFLAGS="$SFLAGS -DNO_snprintf"
711-
echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
712-
echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
713-
echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log
714-
echo " vulnerabilities." | tee -a configure.log
715-
716-
echo >> configure.log
717-
cat >$test.c <<EOF
718-
#include <stdio.h>
719-
int mytest()
720-
{
721-
char buf[20];
722-
return sprintf(buf, "%s", "foo");
723-
}
724-
int main()
725-
{
726-
return (mytest());
727-
}
728-
EOF
729-
730-
if try $CC -c $CFLAGS $test.c; then
731-
echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
732-
else
733-
CFLAGS="$CFLAGS -DHAS_sprintf_void"
734-
SFLAGS="$SFLAGS -DHAS_sprintf_void"
735-
echo "Checking for return value of sprintf()... No." | tee -a configure.log
736-
echo " WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
737-
echo " can build but will be open to possible string-format security" | tee -a configure.log
738-
echo " vulnerabilities." | tee -a configure.log
739-
fi
740-
fi
571+
echo "Checking for ANSI C compliant compiler... No." | tee -a configure.log
572+
echo "Error: ANSI C compatible compiler needed, cannot continue." | tee -a configure.log
573+
leave 1
741574
fi
742575

743576
# see if we can hide zlib internal symbols that are linked between separate source files

crc32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# endif /* !DYNAMIC_CRC_TABLE */
2929
#endif /* MAKECRCH */
3030

31-
#include "zutil.h" /* for STDC definitions */
31+
#include "zutil.h"
3232

3333
#define local static
3434

deflate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void ZLIB_INTERNAL bi_windup OF((deflate_state *s));
351351
#ifndef DEBUG
352352
/* Inline versions of _tr_tally for speed: */
353353

354-
#if defined(GEN_TREES_H) || !defined(STDC)
354+
#if defined(GEN_TREES_H)
355355
extern uch ZLIB_INTERNAL _length_code[];
356356
extern uch ZLIB_INTERNAL _dist_code[];
357357
#else

gzguts.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020

2121
#include <stdio.h>
2222
#include "zlib.h"
23-
#ifdef STDC
24-
# include <string.h>
25-
# include <stdlib.h>
26-
# include <limits.h>
27-
#endif
23+
#include <string.h>
24+
#include <stdlib.h>
25+
#include <limits.h>
2826
#include <fcntl.h>
2927

3028
#ifdef _WIN32
@@ -46,19 +44,11 @@
4644
# define NO_GZCOMPRESS
4745
#endif
4846

49-
#if defined(STDC99) || defined(__CYGWIN__)
50-
# ifndef HAVE_VSNPRINTF
51-
# define HAVE_VSNPRINTF
52-
# endif
53-
#endif
54-
55-
#ifndef HAVE_VSNPRINTF
56-
# ifdef WIN32
5747
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
58-
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
59-
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
60-
# define vsnprintf _vsnprintf
61-
# endif
48+
#if !defined(STDC99) && !defined(__CYGWIN__) && defined(WIN32)
49+
# if !defined(vsnprintf)
50+
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
51+
# define vsnprintf _vsnprintf
6252
# endif
6353
# endif
6454
#endif
@@ -76,12 +66,6 @@
7666
#endif
7767
/* compile with -Dlocal if your debugger can't find static symbols */
7868

79-
/* gz* functions always use library allocation functions */
80-
#ifndef STDC
81-
extern voidp malloc OF((uInt size));
82-
extern void free OF((voidpf ptr));
83-
#endif
84-
8569
/* get errno and strerror definition */
8670
#if defined UNDER_CE
8771
# include <windows.h>

gzlib.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ local gzFile gz_open(path, fd, mode)
210210
*(state->path) = 0;
211211
else
212212
#endif
213-
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
214213
snprintf(state->path, len + 1, "%s", (const char *)path);
215-
#else
216-
strcpy(state->path, path);
217-
#endif
218214

219215
/* compute the flags for open() */
220216
oflag =
@@ -290,11 +286,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
290286

291287
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
292288
return NULL;
293-
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
294289
snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
295-
#else
296-
sprintf(path, "<fd:%d>", fd); /* for debugging */
297-
#endif
298290
gz = gz_open(path, fd, mode);
299291
free(path);
300292
return gz;
@@ -603,14 +595,8 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
603595
state->err = Z_MEM_ERROR;
604596
return;
605597
}
606-
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
607598
snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
608599
"%s%s%s", state->path, ": ", msg);
609-
#else
610-
strcpy(state->msg, state->path);
611-
strcat(state->msg, ": ");
612-
strcat(state->msg, msg);
613-
#endif
614600
return;
615601
}
616602

0 commit comments

Comments
 (0)