From ce342a04922797cb53557178c54d32c4efafda16 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Wed, 6 Jul 2016 21:31:22 -0400 Subject: Document string termination in header files and remove no-longer-needed string termination logic in various places. --- io.c | 1 - 1 file changed, 1 deletion(-) (limited to 'io.c') diff --git a/io.c b/io.c index b9bce694..5ad7913a 100644 --- a/io.c +++ b/io.c @@ -480,7 +480,6 @@ nextfile(IOBUF **curfile, bool skipping) if (arg == NULL || arg->stlen == 0) continue; arg = force_string(arg); - arg->stptr[arg->stlen] = '\0'; if (! do_traditional) { unref(ARGIND_node->var_value); ARGIND_node->var_value = make_number((AWKNUM) i); -- cgit v1.2.3 From cc04afb329cea035d0d9b67cd3b677e06b2f3996 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 12 Nov 2016 19:12:13 +0200 Subject: Further code improvements and doc changes as diff until merge. --- io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 354420b1..4e2c6cf2 100644 --- a/io.c +++ b/io.c @@ -533,7 +533,7 @@ nextfile(IOBUF **curfile, bool skipping) unref(FILENAME_node->var_value); FILENAME_node->var_value = make_string("-", 1); - FILENAME_node->var_value->flags |= MAYBE_NUM; /* be pedantic */ + FILENAME_node->var_value->flags |= USER_INPUT; /* be pedantic */ fname = "-"; iop = iop_alloc(fileno(stdin), fname, 0); *curfile = iop_finish(iop); @@ -2657,7 +2657,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) else { /* assignment to variable */ unref(*lhs); *lhs = make_string(s, cnt); - (*lhs)->flags |= MAYBE_NUM; + (*lhs)->flags |= USER_INPUT; } return make_number((AWKNUM) 1.0); @@ -2700,7 +2700,7 @@ do_getline(int into_variable, IOBUF *iop) lhs = POP_ADDRESS(); unref(*lhs); *lhs = make_string(s, cnt); - (*lhs)->flags |= MAYBE_NUM; + (*lhs)->flags |= USER_INPUT; } return make_number((AWKNUM) 1.0); } -- cgit v1.2.3 From e8b0cf14d975304166c58a2d04a2943ab821367a Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 18 Nov 2016 06:00:17 +0200 Subject: Audit use of stptr for NUL termination. Update doc before merge to master. --- io.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 4e2c6cf2..688723fd 100644 --- a/io.c +++ b/io.c @@ -957,7 +957,7 @@ redirect_string(const char *str, size_t explen, bool not_string, #endif direction = "to/from"; if (! two_way_open(str, rp, extfd)) { - if (! failure_fatal || is_non_fatal_redirect(str)) { + if (! failure_fatal || is_non_fatal_redirect(str, explen)) { *errflg = errno; /* do not free rp, saving it for reuse (save_rp = rp) */ return NULL; @@ -1044,7 +1044,7 @@ redirect_string(const char *str, size_t explen, bool not_string, */ if (errflg != NULL) *errflg = errno; - if (failure_fatal && ! is_non_fatal_redirect(str) && + if (failure_fatal && ! is_non_fatal_redirect(str, explen) && (redirtype == redirect_output || redirtype == redirect_append)) { /* multiple messages make life easier for translators */ @@ -1125,10 +1125,21 @@ is_non_fatal_std(FILE *fp) /* is_non_fatal_redirect --- return true if redirected I/O should be nonfatal */ bool -is_non_fatal_redirect(const char *str) +is_non_fatal_redirect(const char *str, size_t len) { - return in_PROCINFO(nonfatal, NULL, NULL) != NULL - || in_PROCINFO(str, nonfatal, NULL) != NULL; + bool ret; + char save; + char *s = (char *) str; + + save = s[len]; + s[len] = '\0'; + + ret = in_PROCINFO(nonfatal, NULL, NULL) != NULL + || in_PROCINFO(s, nonfatal, NULL) != NULL; + + s[len] = save; + + return ret; } /* close_one --- temporarily close an open file to re-use the fd */ @@ -1182,7 +1193,11 @@ do_close(int nargs) if (nargs == 2) { /* 2nd arg if present: "to" or "from" for two-way pipe */ /* DO NOT use _() on the strings here! */ + char save; + tmp2 = POP_STRING(); + save = tmp2->stptr[tmp2->stlen]; + tmp2->stptr[tmp2->stlen] = '\0'; if (strcasecmp(tmp2->stptr, "to") == 0) how = CLOSE_TO; else if (strcasecmp(tmp2->stptr, "from") == 0) @@ -1191,6 +1206,7 @@ do_close(int nargs) DEREF(tmp2); fatal(_("close: second argument must be `to' or `from'")); } + tmp2->stptr[tmp2->stlen] = save; DEREF(tmp2); } @@ -1733,7 +1749,7 @@ devopen(const char *name, const char *mode) unsigned long retries = 0; static long msleep = 1000; bool hard_error = false; - bool non_fatal = is_non_fatal_redirect(name); + bool non_fatal = is_non_fatal_redirect(name, strlen(name)); cp = (char *) name; @@ -2619,7 +2635,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) } return make_number((AWKNUM) -1.0); } else if ((rp->flag & RED_TWOWAY) != 0 && rp->iop == NULL) { - if (is_non_fatal_redirect(redir_exp->stptr)) { + if (is_non_fatal_redirect(redir_exp->stptr, redir_exp->stlen)) { update_ERRNO_int(EBADF); return make_number((AWKNUM) -1.0); } -- cgit v1.2.3