summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-06-23 22:44:11 +0000
committerMike Frysinger <vapier@gentoo.org>2005-06-23 22:44:11 +0000
commit5fbbe119a445a736c281fa7715be8a64f187befa (patch)
tree9495046d9fbcb76fdd8fdfb6a33f690de771dabe /sci-calculators
parentUse KERNEL_DIR instead of /usr/src/linux for the kernel source tree (bug #968... (diff)
downloadhistorical-5fbbe119a445a736c281fa7715be8a64f187befa.tar.gz
historical-5fbbe119a445a736c281fa7715be8a64f187befa.tar.bz2
historical-5fbbe119a445a736c281fa7715be8a64f187befa.zip
Fix misc overflows, and support for more operators, etc...
Package-Manager: portage-2.0.51.22-r1
Diffstat (limited to 'sci-calculators')
-rw-r--r--sci-calculators/pcalc/ChangeLog15
-rw-r--r--sci-calculators/pcalc/Manifest24
-rw-r--r--sci-calculators/pcalc/files/digest-pcalc-1.0.0-r11
-rw-r--r--sci-calculators/pcalc/files/pcalc-1.0.0-duplicated-case.patch21
-rw-r--r--sci-calculators/pcalc/files/pcalc-1.0.0-error-handler.patch26
-rw-r--r--sci-calculators/pcalc/files/pcalc-1.0.0-input-overflow-check.patch40
-rw-r--r--sci-calculators/pcalc/files/pcalc-1.0.0-operator-updates.patch106
-rw-r--r--sci-calculators/pcalc/files/pcalc-1.0.0-static-vars.patch49
-rw-r--r--sci-calculators/pcalc/files/pcalc-1.0.0-string-overflow-checks.patch41
-rw-r--r--sci-calculators/pcalc/files/pcalc-1.0.0-tmpfile.patch76
-rw-r--r--sci-calculators/pcalc/files/pcalc-1.0.0-usage.patch23
-rw-r--r--sci-calculators/pcalc/pcalc-1.0.0-r1.ebuild43
12 files changed, 462 insertions, 3 deletions
diff --git a/sci-calculators/pcalc/ChangeLog b/sci-calculators/pcalc/ChangeLog
index 548461eb4813..dfde8573c460 100644
--- a/sci-calculators/pcalc/ChangeLog
+++ b/sci-calculators/pcalc/ChangeLog
@@ -1,6 +1,19 @@
# ChangeLog for sci-calculators/pcalc
# Copyright 1999-2005 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/sci-calculators/pcalc/ChangeLog,v 1.1 2005/03/30 05:53:42 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/sci-calculators/pcalc/ChangeLog,v 1.2 2005/06/23 22:44:11 vapier Exp $
+
+*pcalc-1.0.0-r1 (23 Jun 2005)
+
+ 23 Jun 2005; Mike Frysinger <vapier@gentoo.org>
+ +files/pcalc-1.0.0-duplicated-case.patch,
+ +files/pcalc-1.0.0-error-handler.patch,
+ +files/pcalc-1.0.0-input-overflow-check.patch,
+ +files/pcalc-1.0.0-operator-updates.patch,
+ +files/pcalc-1.0.0-static-vars.patch,
+ +files/pcalc-1.0.0-string-overflow-checks.patch,
+ +files/pcalc-1.0.0-tmpfile.patch, +files/pcalc-1.0.0-usage.patch,
+ +pcalc-1.0.0-r1.ebuild:
+ Fix misc overflows, and support for more operators, etc...
*pcalc-1.0.0 (30 Mar 2005)
diff --git a/sci-calculators/pcalc/Manifest b/sci-calculators/pcalc/Manifest
index 13a167442ef6..dc248597ba67 100644
--- a/sci-calculators/pcalc/Manifest
+++ b/sci-calculators/pcalc/Manifest
@@ -1,4 +1,24 @@
-MD5 050e9516a42e9449715ec6231865ed4a pcalc-1.0.0.ebuild 703
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
MD5 25822404d543970f374c03c190602347 metadata.xml 217
-MD5 a65811c769e646711b93cc5de916cb3e ChangeLog 338
+MD5 16cd266216c2f9bb9d5dbcb736451f07 pcalc-1.0.0-r1.ebuild 1120
+MD5 050e9516a42e9449715ec6231865ed4a pcalc-1.0.0.ebuild 703
+MD5 aa9fc05b6c68170d3f7c898afdc03175 ChangeLog 846
+MD5 ca434e3472d0fc8b9da24dc053a7929f files/digest-pcalc-1.0.0-r1 61
+MD5 e36de7ac01ab409f77bf06a356099b38 files/pcalc-1.0.0-duplicated-case.patch 653
+MD5 127ca758677a0ee0e12a564d390f1de6 files/pcalc-1.0.0-string-overflow-checks.patch 935
+MD5 44100658fc8c1627d8d7833fa95ad814 files/pcalc-1.0.0-static-vars.patch 1118
MD5 ca434e3472d0fc8b9da24dc053a7929f files/digest-pcalc-1.0.0 61
+MD5 800c5fe897cd8901c8b5671fcb17b11f files/pcalc-1.0.0-usage.patch 785
+MD5 37048896f8eadea6e20d6d4ba67c2d5f files/pcalc-1.0.0-operator-updates.patch 3712
+MD5 b6ec72ff82cd4a5d80a40e5f8ccc6d67 files/pcalc-1.0.0-error-handler.patch 746
+MD5 4d66ff33f60981fcadd27d915a6c0c7f files/pcalc-1.0.0-input-overflow-check.patch 974
+MD5 868aa5ef1f69bce9df43d429023026d9 files/pcalc-1.0.0-tmpfile.patch 1946
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.1 (GNU/Linux)
+
+iD8DBQFCuztOgIKl8Uu19MoRAsn2AJ47lzlCSI37zvHknQI+Rov02o6wGQCeOUUY
+ubWUpRUSInK1NR8kZTx9tnQ=
+=C/ZU
+-----END PGP SIGNATURE-----
diff --git a/sci-calculators/pcalc/files/digest-pcalc-1.0.0-r1 b/sci-calculators/pcalc/files/digest-pcalc-1.0.0-r1
new file mode 100644
index 000000000000..6e1788842d28
--- /dev/null
+++ b/sci-calculators/pcalc/files/digest-pcalc-1.0.0-r1
@@ -0,0 +1 @@
+MD5 19ba589b61b7c302ca4570a6c75a4df1 pcalc-000.tar.gz 103437
diff --git a/sci-calculators/pcalc/files/pcalc-1.0.0-duplicated-case.patch b/sci-calculators/pcalc/files/pcalc-1.0.0-duplicated-case.patch
new file mode 100644
index 000000000000..9b734fb90fdd
--- /dev/null
+++ b/sci-calculators/pcalc/files/pcalc-1.0.0-duplicated-case.patch
@@ -0,0 +1,21 @@
+The \".*\" case is duplicated, remove the useless version ;).
+
+--- pcalc-000/pcalcl.l
++++ pcalc-000/pcalcl.l
+@@ -287,16 +287,6 @@
+ #endif
+ }
+
+-\".*\" {
+- #ifdef TEST
+- printf(" String: [ %s ]\n", yytext);
+- #endif
+-
+- #ifdef RET_EACH
+- //return(STR);
+- #endif
+- }
+-
+ ";" {
+ count();
+
diff --git a/sci-calculators/pcalc/files/pcalc-1.0.0-error-handler.patch b/sci-calculators/pcalc/files/pcalc-1.0.0-error-handler.patch
new file mode 100644
index 000000000000..fc1980e84644
--- /dev/null
+++ b/sci-calculators/pcalc/files/pcalc-1.0.0-error-handler.patch
@@ -0,0 +1,26 @@
+We can't use execerror yet because it assumes the jumpbuf has
+been setup which it hasn't just yet. Dump errors with fprintf
+to stderr instead.
+
+Patch by Mike Frysinger <vapier@gentoo.org>
+
+--- pcalc-000/pcalc.y
++++ pcalc-000/pcalc.y
+@@ -188,7 +188,7 @@
+ yyin = fopen(&argv[1][1], "rt");
+ if(!yyin)
+ {
+- printf("Cannot find file.\n");
++ fprintf(stderr, "Cannot find file.\n");
+ exit(0);
+ }
+ }
+@@ -211,7 +211,7 @@
+
+ if(!yyin)
+ {
+- execerror( "cannot create tmp file\n", NULL); exit(0);
++ fprintf(stderr, "cannot create tmp file\n"); exit(0);
+ }
+ fwrite(buff, len, 1, yyin);
+ fputc('\n', yyin);
diff --git a/sci-calculators/pcalc/files/pcalc-1.0.0-input-overflow-check.patch b/sci-calculators/pcalc/files/pcalc-1.0.0-input-overflow-check.patch
new file mode 100644
index 000000000000..fc706c106e40
--- /dev/null
+++ b/sci-calculators/pcalc/files/pcalc-1.0.0-input-overflow-check.patch
@@ -0,0 +1,40 @@
+Make sure we don't blow up if the user enters a lot of stuff (buff is
+normally a char[512], so if user gives us 5000 chars ...).
+
+Also trim unused/duplicated variables.
+
+Patch by Mike Frysinger <vapier@gentoo.org>
+
+--- pcalc-000/pcalc.y
++++ pcalc-000/pcalc.y
+@@ -148,13 +148,6 @@
+ int (*ptr_getchar)();
+ int (*ptr_ungetc)();
+
+-FILE *in_fp = NULL;
+-
+-int len;
+-char buff[512];
+-
+-FILE *in_fp;
+-
+ int main(int argc, char *argv[])
+
+ {
+@@ -203,8 +203,16 @@
+ int len, cnt;
+ int tmpfile;
++ char buff[512];
+
++ len = 0;
+ for(cnt = args+1; cnt < argc; cnt++)
+ {
++ len += strlen(argv[cnt]) + 1;
++ if (len >= sizeof(buff))
++ {
++ fprintf(stderr, "Input is too long (max of %lu chars allowed)\n", (unsigned long)sizeof(buff));
++ exit(1);
++ }
+ strcat(buff, argv[cnt]); strcat(buff, " ");
+ }
+
diff --git a/sci-calculators/pcalc/files/pcalc-1.0.0-operator-updates.patch b/sci-calculators/pcalc/files/pcalc-1.0.0-operator-updates.patch
new file mode 100644
index 000000000000..438b39b0e772
--- /dev/null
+++ b/sci-calculators/pcalc/files/pcalc-1.0.0-operator-updates.patch
@@ -0,0 +1,106 @@
+Change operator order so that binary 'or' and binary 'and' are
+not on the same level, but so that 'and' comes before 'or'.
+This is to match the standard C precedence.
+
+Also add support for the % (modulus), < (binary left shift),
+and > (binary right shift) operators.
+
+Patch by Mike Frysinger <vapier@gentoo.org>
+
+--- pcalc-000/README
++++ pcalc-000/README
+@@ -60,10 +60,12 @@
+ Operator priorities:
+
+- LOW '=' assignment
+- or and binary or/binary and
+- '+' '-' addition/subtruction
+- '*' '/' multiply/divide
+- '-' unary minus
+- HIGH '^' exponentation
++ LOW '=' assignment
++ or binary or
++ and binary and
++ '>' '<' binary left/right shift
++ '+' '-' addition/subtruction
++ '*' '/' '%' multiply/divide/modulus
++ '-' unary minus
++ HIGH '^' exponentation
+
+ Syntax:
+--- pcalc-000/help.c
++++ pcalc-000/help.c
+@@ -40,5 +40,5 @@
+ \n\
+ Operators:\n\
+- '+' '-' '*' '/' '^'\n\
++ '+' '-' '*' '/' '%' '^'\n\
+ \n\
+ Constants: (case sensitive)\n\
+@@ -81,10 +81,12 @@
+ Operator priorities:\n\
+ \n\
+- right assotiation: '=' ASSIGNMENT\n\
+- left assotiation: or and BINARY OR/BINARY AND\n\
+- left assotiation: '+' '-' ADDITION/SUBTRUCTION\n\
+- left assotiation: '*' '/' MULTIPLY/DIVIDE\n\
+- left assotiation: '-' UNARY MINUS\n\
+- right assotiation: '^' EXPONENTATION\n\
++ right assotiation: '=' ASSIGNMENT\n\
++ left assotiation: or BINARY OR\n\
++ left assotiation: and BINARY AND\n\
++ left assotiation: '<' '>' BINARY LEFT/RIGHT SHIFT\n\
++ left assotiation: '+' '-' ADDITION/SUBTRUCTION\n\
++ left assotiation: '*' '/' '%' MULTIPLY/DIVIDE\n\
++ left assotiation: '-' UNARY MINUS\n\
++ right assotiation: '^' EXPONENTATION\n\
+ \n\
+ ");
+--- pcalc-000/pcalc.txt
++++ pcalc-000/pcalc.txt
+@@ -59,10 +59,12 @@
+ Operator priorities:
+
+- LOW '=' assignment
+- or and binary or/binary and
+- '+' '-' addition/subtruction
+- '*' '/' multiply/divide
+- '-' unary minus
+- HIGH '^' exponentation
++ LOW '=' assignment
++ or binary or
++ and binary and
++ '<' '>' binary left/right shift
++ '+' '-' addition/subtruction
++ '*' '/' '%' multiply/divide/modulus
++ '-' unary minus
++ HIGH '^' exponentation
+
+ Syntax:
+--- pcalc-000/pcalc.y
++++ pcalc-000/pcalc.y
+@@ -59,7 +59,9 @@
+
+ %right '='
+-%left '|' '&'
++%left '|'
++%left '&'
++%left '<' '>'
+ %left '+' '-'
+-%left '*' '/'
++%left '*' '/' '%'
+ %left UNARYMINUS
+ %right '^' /* exponentiation */
+@@ -113,4 +113,6 @@
+ | expr '|' expr { $$ = (long)$1 | (long)$3 ;}
+ | expr '&' expr { $$ = (long)$1 & (long)$3 ;}
++ | expr '<' expr { $$ = (long)$1 << (long)$3 ; }
++ | expr '>' expr { $$ = (long)$1 >> (long)$3 ; }
+ | expr '+' expr { $$ = $1 + $3 ; }
+ | expr '-' expr { $$ = $1 - $3 ; }
+@@ -119,4 +120,5 @@
+ $$ = $1 / $3 ;
+ }
++ | expr '%' expr { $$ = (long)$1 % (long)$3 ; }
+ | expr '^' expr { $$ = Pow( $1, $3) ; }
+ | '(' expr ')' { $$ = $2 ; }
diff --git a/sci-calculators/pcalc/files/pcalc-1.0.0-static-vars.patch b/sci-calculators/pcalc/files/pcalc-1.0.0-static-vars.patch
new file mode 100644
index 000000000000..8f569a958ba4
--- /dev/null
+++ b/sci-calculators/pcalc/files/pcalc-1.0.0-static-vars.patch
@@ -0,0 +1,49 @@
+Declare all the work_str vars static since they'll conflict badly
+with each other if we don't. pcalc.y doesn't actually use work_str.
+
+Patch by Mike Frysinger <vapier@gentoo.org>
+
+--- pcalc-000/funct.c
++++ pcalc-000/funct.c
+@@ -50,7 +50,7 @@
+
+ /* -------- Strings: ----------------------------------------------------- */
+
+-char work_str[2000];
++static char work_str[2000];
+
+ /* -------- Implementation: ---------------------------------------------- */
+
+--- pcalc-000/pcalc.y
++++ pcalc-000/pcalc.y
+@@ -37,7 +37,7 @@
+
+ extern FILE * yyin ;
+
+- char work_str[128];
++ //static char work_str[128];
+
+ %}
+
+--- pcalc-000/print.c
++++ pcalc-000/print.c
+@@ -31,7 +31,7 @@
+
+ /* -------- Implementation: ---------------------------------------------- */
+
+-char work_str[128];
++static char work_str[128];
+
+ void print_num(double var)
+
+--- pcalc-000/store.c
++++ pcalc-000/store.c
+@@ -27,7 +27,7 @@
+
+ /* -------- Implementation: ---------------------------------------------- */
+
+-char work_str[128];
++static char work_str[128];
+
+ int store(char *file, char *name, double var)
+
diff --git a/sci-calculators/pcalc/files/pcalc-1.0.0-string-overflow-checks.patch b/sci-calculators/pcalc/files/pcalc-1.0.0-string-overflow-checks.patch
new file mode 100644
index 000000000000..90eb32edfd0a
--- /dev/null
+++ b/sci-calculators/pcalc/files/pcalc-1.0.0-string-overflow-checks.patch
@@ -0,0 +1,41 @@
+Make sure we don't overflow buffers if input is really big.
+
+Also move the string array to local scope.
+
+Patch by Mike Frysinger <vapier@gentoo.org>
+
+--- str.c
++++ str.c
+@@ -103,4 +103,11 @@
+ break;
+ }
++ else if(str2-str+1 >= lim)
++ {
++ fprintf(stderr, "String too large for buffer of %i chars; truncated\n", lim-1);
++ ret_val = FALSE;
++ *str2 = '\0';
++ break;
++ }
+ switch(*str2)
+ {
+--- funct.c
++++ funct.c
+@@ -88,5 +88,4 @@
+ }
+
+-char string[128];
+
+ /* the date function */
+@@ -97,4 +96,5 @@
+ struct tm *loc_time;
+ time_t lt;
++ char string[128];
+
+ lt = time(NULL);
+@@ -102,5 +102,5 @@
+ str_esc(str, work_str, sizeof(work_str));
+ loc_time = localtime(&lt);
+- strftime(string, 128, work_str, loc_time);
++ strftime(string, sizeof(string), work_str, loc_time);
+
+ printf("%s", string);
diff --git a/sci-calculators/pcalc/files/pcalc-1.0.0-tmpfile.patch b/sci-calculators/pcalc/files/pcalc-1.0.0-tmpfile.patch
new file mode 100644
index 000000000000..836a0cfd74f5
--- /dev/null
+++ b/sci-calculators/pcalc/files/pcalc-1.0.0-tmpfile.patch
@@ -0,0 +1,76 @@
+Fix the tempfile handling to avoid race conditions. Also use /tmp as
+a fallback if $PWD is read-only for whatever reason.
+
+Patch by Mike Frysinger <vapier@gentoo.org>
+
+--- pcalc-000/pcalc.y
++++ pcalc-000/pcalc.y
+@@ -151,7 +151,10 @@
+ int main(int argc, char *argv[])
+
+ {
+- int comm = 0, args;
++ int args;
++ char template_local[] = "pcalc.tmp.XXXXXX",
++ template_global[] = "/tmp/pcalc.tmp.XXXXXX",
++ *template;
+ char *env;
+
+ args = parse_comline(argc, argv);
+@@ -198,6 +199,7 @@
+
+ char *commandline;
+ int len, cnt;
++ int tmpfile;
+
+ for(cnt = args+1; cnt < argc; cnt++)
+ {
+@@ -207,19 +209,24 @@
+ //printf("CMDLINE='%s'\n", buff);
+
+ len = strlen(buff);
+- yyin = fopen("pcalc.tmp", "w");
++ template = template_local;
++ tmpfile = mkstemp(template);
+
+- if(!yyin)
++ if(tmpfile == -1)
+ {
+- fprintf(stderr, "cannot create tmp file\n"); exit(0);
++ template = template_global;
++ tmpfile = mkstemp(template);
++ if(tmpfile == -1)
++ {
++ fprintf(stderr, "cannot create tmp file\n"); exit(0);
++ }
+ }
+- fwrite(buff, len, 1, yyin);
+- fputc('\n', yyin);
+- //fputc(0x1a, yyin);
+- fclose(yyin);
++ write(tmpfile, buff, len);
++ write(tmpfile, "\n", 1);
++ //write(tmpfile, "\x1a", 1);
++ lseek(tmpfile, 0, SEEK_SET);
+
+- yyin = fopen("pcalc.tmp", "r");
+- comm = 1;
++ yyin = fdopen(tmpfile, "r");
+ }
+
+ init_sym() ;
+@@ -228,10 +229,10 @@
+ yyparse() ;
+
+ if(yyin)
+- fclose(yyin);
+-
+- if(comm)
+- unlink("pcalc.tmp");
++ {
++ unlink(template); /* unlink before we close to avoid race */
++ fclose(yyin); /* this closes tmpfile too */
++ }
+
+ return 0 ;
+ }
diff --git a/sci-calculators/pcalc/files/pcalc-1.0.0-usage.patch b/sci-calculators/pcalc/files/pcalc-1.0.0-usage.patch
new file mode 100644
index 000000000000..55f526fbfcc3
--- /dev/null
+++ b/sci-calculators/pcalc/files/pcalc-1.0.0-usage.patch
@@ -0,0 +1,23 @@
+Add support for the -h switch.
+
+--- pcalc-000/pcalc.y
++++ pcalc-000/pcalc.y
+@@ -315,6 +315,18 @@
+ {
+ switch(argv[i][1])
+ {
++ case 'h' :
++ printf (
++ "\nProgrammer's calculator by Peter Glen.\n\n"
++ "Usage: pcalc <stuff to calculate>\n"
++ " pcalc @script\n"
++ "\nOptions:\n"
++ " -s,-S silent mode\n"
++ " -b,-B silent mode\n"
++ " -v version\n"
++ " -h help\n"
++ "\nFor more info, run pcalc without any options, or see the README.\n\n");
++
+ case 'S' : /* quiet mode */
+ case 's' :
+ fSilent = 1;
diff --git a/sci-calculators/pcalc/pcalc-1.0.0-r1.ebuild b/sci-calculators/pcalc/pcalc-1.0.0-r1.ebuild
new file mode 100644
index 000000000000..38b9053a6d11
--- /dev/null
+++ b/sci-calculators/pcalc/pcalc-1.0.0-r1.ebuild
@@ -0,0 +1,43 @@
+# Copyright 1999-2005 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/sci-calculators/pcalc/pcalc-1.0.0-r1.ebuild,v 1.1 2005/06/23 22:44:11 vapier Exp $
+
+inherit eutils
+
+DESCRIPTION="the programmers calculator"
+HOMEPAGE="http://ibiblio.org/pub/Linux/apps/math/calc/pcalc.lsm"
+SRC_URI="http://ibiblio.org/pub/Linux/apps/math/calc/pcalc-000.tar.gz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE=""
+
+DEPEND="sys-devel/flex
+ sys-devel/bison"
+RDEPEND=""
+
+S=${WORKDIR}/${PN}-000
+
+src_unpack() {
+ unpack ${A}
+ cd "${S}"
+ rm -f pcalc
+ epatch "${FILESDIR}"/${P}-static-vars.patch
+ epatch "${FILESDIR}"/${P}-error-handler.patch
+ epatch "${FILESDIR}"/${P}-tmpfile.patch
+ epatch "${FILESDIR}"/${P}-input-overflow-check.patch
+ epatch "${FILESDIR}"/${P}-operator-updates.patch
+ epatch "${FILESDIR}"/${P}-usage.patch
+ epatch "${FILESDIR}"/${P}-string-overflow-checks.patch
+ epatch "${FILESDIR}"/${P}-duplicated-case.patch
+}
+
+src_test() {
+ make test || die "make test failed :("
+}
+
+src_install() {
+ dobin pcalc || die "dobin pcalc"
+ dodoc EXAMPLE README
+}