FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

try_to_get_string() can fail even if isstringvalue() return TRUE · gnuplot/gnuplot@a87187b · GitHub

Repository navigation

Commit a87187b

Browse files
Ethan A Merritt
committed
try_to_get_string() can fail even if isstringvalue() return TRUE
1 parent eb80be3 commit a87187b

8 files changed

Lines changed: 35 additions & 25 deletions

File tree

‎ChangeLog‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2015-07-08 Ethan A Merritt <merritt@u.washington.edu>
2+
3+
* term/estimate.trm: Initialization of enhanced text string buffer.
4+
Bug #1648
5+
6+
* src/set.c src/fit.c src/term.c src/parse.c term/cgm.trm term/gd.trm
7+
term/x11.trm: Fuzz-testing found a recurring pattern of fragile code:
8+
if (isstringvalue(c_token))
9+
foo = try_to_get_string(); /* cannot fail */
10+
Unfortunately it _can_ fail if an expression begins with a quoted string
11+
but is coerced into returning a numerical value. All of these sites
12+
require a specific for (foo != NULL).
13+
Bug #1649
14+
115
2015-07-05 Ethan A Merritt <merritt@u.washington.edu>
216

317
* src/wxterminal/gp_cairo.c (gp_cairo_set_dashtype): If the dashtype

‎src/fit.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: fit.c,v 1.156 2015/04/24 22:07:39 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: fit.c,v 1.157 2015/06/05 20:49:10 broeker Exp $"); }
33
#endif
44

55
/* NOTICE: Change of Copyright Status
@@ -2354,11 +2354,11 @@ fit_command()
23542354

23552355
static char *viafile = NULL;
23562356
free(viafile); /* Free previous name, if any */
2357-
viafile = try_to_get_string(); /* Cannot fail since isstringvalue succeeded */
2357+
viafile = try_to_get_string();
2358+
if (!viafile || !(f = loadpath_fopen(viafile, "r")))
2359+
Eex2("could not read parameter-file \"%s\"", viafile);
23582360
if (!fit_suppress_log)
23592361
fprintf(log_f, "fitted parameters and initial values from file: %s\n\n", viafile);
2360-
if (!(f = loadpath_fopen(viafile, "r")))
2361-
Eex2("could not read parameter-file \"%s\"", viafile);
23622362

23632363
/* get parameters and values out of file and ignore fixed ones */
23642364

‎src/parse.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: parse.c,v 1.92 2015/01/21 03:38:24 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: parse.c,v 1.93 2015/06/03 22:55:46 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - parse.c */
@@ -200,10 +200,8 @@ string_or_express(struct at_type **atptr)
200200
if (equals(c_token,"$"))
201201
return parse_datablock_name();
202202

203-
if (isstring(c_token)) {
204-
str = try_to_get_string();
203+
if (isstring(c_token) && (str = try_to_get_string()))
205204
return str;
206-
}
207205

208206
/* parse expression */
209207
temp_at();

‎src/set.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: set.c,v 1.489 2015/05/08 18:17:08 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: set.c,v 1.490 2015/05/08 18:32:12 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - set.c */
@@ -1628,11 +1628,11 @@ set_encoding()
16281628
#endif
16291629
} else {
16301630
int temp = lookup_table(&set_encoding_tbl[0],c_token);
1631+
char *senc;
16311632

16321633
/* allow string variables as parameter */
1633-
if ((temp == S_ENC_INVALID) && isstringvalue(c_token)) {
1634+
if ((temp == S_ENC_INVALID) && isstringvalue(c_token) && (senc = try_to_get_string())) {
16341635
int i;
1635-
char *senc = try_to_get_string();
16361636
for (i = 0; encoding_names[i] != NULL; i++)
16371637
if (strcmp(encoding_names[i], senc) == 0)
16381638
temp = i;

‎src/term.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: term.c,v 1.314 2015/06/14 18:06:59 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: term.c,v 1.315 2015/06/15 23:24:35 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - term.c */
@@ -1418,8 +1418,7 @@ set_term()
14181418
if (!END_OF_COMMAND) {
14191419
input_name = gp_input_line + token[c_token].start_index;
14201420
t = change_term(input_name, token[c_token].length);
1421-
if (!t && isstringvalue(c_token)) {
1422-
input_name = try_to_get_string(); /* Cannot fail if isstringvalue succeeded */
1421+
if (!t && isstringvalue(c_token) && (input_name = try_to_get_string())) {
14231422
t = change_term(input_name, strlen(input_name));
14241423
free(input_name);
14251424
} else {

‎term/cgm.trm‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Hey Emacs this is -*- C -*-
2-
* $Id: cgm.trm,v 1.98 2012/11/25 22:01:22 sfeam Exp $
2+
* $Id: cgm.trm,v 1.99 2012/12/21 23:05:17 sfeam Exp $
33
*/
44

55
/* GNUPLOT - cgm.trm */
@@ -457,12 +457,12 @@ CGM_options()
457457
cgm_user_color_count++;
458458
++c_token;
459459
} else {
460+
char *s = NULL;
460461
if (equals(c_token,"font"))
461462
c_token++;
462-
if (isstringvalue(c_token)) {
463+
if (isstringvalue(c_token) && (s = try_to_get_string())) {
463464
double relwidth;
464465
int font_index;
465-
char *s = try_to_get_string();
466466
char *comma = strchr(s,',');
467467
if (comma && (1 == sscanf(comma+1,"%d",&cgm_fontsize)))
468468
*comma = '\0';

‎term/gd.trm‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Hello, Emacs, this is -*-C-*-
2-
* $Id: gd.trm,v 1.181 2015/01/11 05:20:50 sfeam Exp $
2+
* $Id: gd.trm,v 1.182 2015/02/18 20:37:39 sfeam Exp $
33
*/
44

55
/* GNUPLOT -- gd.trm */
@@ -770,9 +770,9 @@ PNG_options()
770770
} else {
771771
int brect[8];
772772
char *err;
773+
char *s;
773774

774-
if (isstringvalue(c_token)) {
775-
char *s = try_to_get_string();
775+
if (isstringvalue(c_token) && (s = try_to_get_string())) {
776776
char *comma = strrchr(s,',');
777777
double fontsize;
778778
if (comma && (1 == sscanf(comma+1,"%lf",&fontsize))) {

‎term/x11.trm‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Hello, Emacs, this is -*-C-*-
2-
* $Id: x11.trm,v 1.224 2015/02/15 16:39:23 broeker Exp $
2+
* $Id: x11.trm,v 1.225 2015/03/29 17:26:00 sfeam Exp $
33
*
44
*/
55

@@ -453,6 +453,7 @@ X11_options()
453453
unsigned long existing_X11_window_id = 0;
454454
TBOOLEAN set_window = FALSE;
455455
#endif
456+
char *s;
456457

457458
do_raise = ctrlq = UNSET;
458459
dashedlines = yes;
@@ -537,8 +538,7 @@ X11_options()
537538
c_token++;
538539
if (END_OF_COMMAND)
539540
int_error(c_token, "expecting font name");
540-
if (isstringvalue(c_token)) {
541-
char *s = try_to_get_string();
541+
if (isstringvalue(c_token) && (s = try_to_get_string())) {
542542
strncpy(X11_default_font, s, sizeof(X11_default_font));
543543
free(s);
544544
} else {
@@ -719,8 +719,7 @@ X11_options()
719719
c_token = c_title_token;
720720
strncat(term_options, " title \"", sizeof(term_options)-strlen(term_options)-1);
721721
title = term_options + strlen(term_options);
722-
if (isstringvalue(c_title_token)) {
723-
char *s = try_to_get_string();
722+
if (isstringvalue(c_title_token) && (s = try_to_get_string())) {
724723
strncat(term_options, s, sizeof(term_options)-strlen(term_options)-1);
725724
free(s);
726725
} else

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL