diff --git a/agi/eagi-sphinx-test.c b/agi/eagi-sphinx-test.c index d2898763c3822fa01cedf642fafe8374d534f092..4d13db507917ceae0722dcf7c90b7e06b7ccb812 100644 --- a/agi/eagi-sphinx-test.c +++ b/agi/eagi-sphinx-test.c @@ -79,7 +79,9 @@ static int read_environment(void) char *val; /* Read environment */ for(;;) { - fgets(buf, sizeof(buf), stdin); + if (!fgets(buf, sizeof(buf), stdin)) { + return -1; + } if (feof(stdin)) return -1; buf[strlen(buf) - 1] = '\0'; @@ -130,7 +132,9 @@ static char *wait_result(void) return NULL; } if (FD_ISSET(STDIN_FILENO, &fds)) { - fgets(astresp, sizeof(astresp), stdin); + if (!fgets(astresp, sizeof(astresp), stdin)) { + return NULL; + } if (feof(stdin)) { fprintf(stderr, "Got hungup on apparently\n"); return NULL; @@ -141,9 +145,10 @@ static char *wait_result(void) } if (FD_ISSET(AUDIO_FILENO, &fds)) { res = read(AUDIO_FILENO, audiobuf, sizeof(audiobuf)); - if (res > 0) { - if (sphinx_sock > -1) - write(sphinx_sock, audiobuf, res); + if ((res > 0) && (sphinx_sock > -1)) { + if (write(sphinx_sock, audiobuf, res) < 0) { + fprintf(stderr, "write() failed: %s\n", strerror(errno)); + } } } if ((sphinx_sock > -1) && FD_ISSET(sphinx_sock, &fds)) { diff --git a/agi/eagi-test.c b/agi/eagi-test.c index 704fd7b22c0553232dc2a8702086973be1ad973d..c40b85d1eabdc5c134e0f51439aae4987bd5bdca 100644 --- a/agi/eagi-test.c +++ b/agi/eagi-test.c @@ -24,7 +24,9 @@ static int read_environment(void) char *val; /* Read environment */ for(;;) { - fgets(buf, sizeof(buf), stdin); + if (!fgets(buf, sizeof(buf), stdin)) { + return -1; + } if (feof(stdin)) return -1; buf[strlen(buf) - 1] = '\0'; @@ -68,7 +70,9 @@ static char *wait_result(void) return NULL; } if (FD_ISSET(STDIN_FILENO, &fds)) { - fgets(astresp, sizeof(astresp), stdin); + if (!fgets(astresp, sizeof(astresp), stdin)) { + return NULL; + } if (feof(stdin)) { fprintf(stderr, "Got hungup on apparently\n"); return NULL; diff --git a/apps/app_adsiprog.c b/apps/app_adsiprog.c index f35a81eea839b289c2a5d1ea844add4b964b07e2..126068c94dd4ec23e619ed2332e4ce27c6c33f60 100644 --- a/apps/app_adsiprog.c +++ b/apps/app_adsiprog.c @@ -1379,7 +1379,9 @@ static struct adsi_script *compile_script(char *script) /* Create "main" as first subroutine */ getsubbyname(scr, "main", NULL, 0); while (!feof(f)) { - fgets(buf, sizeof(buf), f); + if (!fgets(buf, sizeof(buf), f)) { + continue; + } if (!feof(f)) { lineno++; /* Trim off trailing return */ diff --git a/apps/app_authenticate.c b/apps/app_authenticate.c index 10d0b2f7342a4e44191140e7cd404ffa505594f8..69abf6f38b0c4c998a9e41e30ca5c79ba1c0d658 100644 --- a/apps/app_authenticate.c +++ b/apps/app_authenticate.c @@ -181,7 +181,9 @@ static int auth_exec(struct ast_channel *chan, void *data) if (feof(f)) break; - fgets(buf, sizeof(buf), f); + if (!fgets(buf, sizeof(buf), f)) { + continue; + } if (ast_strlen_zero(buf)) continue; diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c index 86ad9e7376b4d2b246550a2badd2b7f958b54f1c..f4a5a5d81f1ea7a4cc7959a87ec8575a627bea15 100644 --- a/apps/app_chanspy.c +++ b/apps/app_chanspy.c @@ -34,6 +34,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include <ctype.h> +#include <errno.h> #include "asterisk/paths.h" /* use ast_config_AST_MONITOR_DIR */ #include "asterisk/file.h" @@ -374,8 +375,11 @@ static int spy_generate(struct ast_channel *chan, void *data, int len, int sampl return -1; } - if (csth->fd) - write(csth->fd, f->data.ptr, f->datalen); + if (csth->fd) { + if (write(csth->fd, f->data.ptr, f->datalen) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } + } ast_frfree(f); diff --git a/apps/app_dial.c b/apps/app_dial.c index b918f23a5092cb37dde5e7d038e38889636aff40..a42edf7a06113c5267c8611f28bd56e1bb07d7af 100644 --- a/apps/app_dial.c +++ b/apps/app_dial.c @@ -2030,10 +2030,16 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ','); if (gosub_argstart) { *gosub_argstart = 0; - asprintf(&gosub_args, "%s,s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], gosub_argstart + 1); + if (asprintf(&gosub_args, "%s,s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], gosub_argstart + 1) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + gosub_args = NULL; + } *gosub_argstart = ','; } else { - asprintf(&gosub_args, "%s,s,1", opt_args[OPT_ARG_CALLEE_GOSUB]); + if (asprintf(&gosub_args, "%s,s,1", opt_args[OPT_ARG_CALLEE_GOSUB]) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + gosub_args = NULL; + } } if (gosub_args) { diff --git a/apps/app_festival.c b/apps/app_festival.c index 82f1bddc598761b3931f6042ed425b431d2b4b10..2d57a51dc9fffe9ff150a7df499401b6052ad8d6 100644 --- a/apps/app_festival.c +++ b/apps/app_festival.c @@ -38,6 +38,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include <signal.h> #include <fcntl.h> #include <ctype.h> +#include <errno.h> #include "asterisk/file.h" #include "asterisk/channel.h" @@ -147,7 +148,11 @@ static int send_waveform_to_fd(char *waveform, int length, int fd) *(waveform + x) = c; } #endif - write(fd, waveform, length); + + if (write(fd, waveform, length) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } + close(fd); exit(0); } @@ -424,17 +429,25 @@ static int festival_exec(struct ast_channel *chan, void *vdata) writecache = 1; strln = strlen(args.text); ast_debug(1, "line length : %d\n", strln); - write(fdesc, &strln, sizeof(strln)); - write(fdesc, args.text, strln); + if (write(fdesc,&strln,sizeof(int)) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } + if (write(fdesc,data,strln) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } seekpos = lseek(fdesc, 0, SEEK_CUR); ast_debug(1, "Seek position : %d\n", seekpos); } } else { - read(fdesc, &strln, sizeof(strln)); + if (read(fdesc,&strln,sizeof(int)) != sizeof(int)) { + ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); + } ast_debug(1, "Cache file exists, strln=%d, strlen=%d\n", strln, (int)strlen(args.text)); if (strlen(args.text) == strln) { ast_debug(1, "Size OK\n"); - read(fdesc, &bigstring, strln); + if (read(fdesc,&bigstring,strln) != strln) { + ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); + } bigstring[strln] = 0; if (strcmp(bigstring, args.text) == 0) { readcache = 1; @@ -464,7 +477,9 @@ static int festival_exec(struct ast_channel *chan, void *vdata) if (writecache == 1) { ast_debug(1, "Writing result to cache...\n"); while ((strln = read(fd, buffer, 16384)) != 0) { - write(fdesc, buffer, strln); + if (write(fdesc,buffer,strln) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } } close(fd); close(fdesc); diff --git a/apps/app_queue.c b/apps/app_queue.c index bc04deb46b13ab5bea17bfddd5aa6fbf41f41cc3..81e82235533fb15d2f3553b3dabae13591999c7a 100644 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -3940,10 +3940,16 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce gosub_argstart = strchr(gosubexec, ','); if (gosub_argstart) { *gosub_argstart = 0; - asprintf(&gosub_args, "%s,s,1(%s)", gosubexec, gosub_argstart + 1); + if (asprintf(&gosub_args, "%s,s,1(%s)", gosubexec, gosub_argstart + 1) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + gosub_args = NULL; + } *gosub_argstart = '|'; } else { - asprintf(&gosub_args, "%s,s,1", gosubexec); + if (asprintf(&gosub_args, "%s,s,1", gosubexec) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + gosub_args = NULL; + } } if (gosub_args) { res = pbx_exec(qe->chan, application, gosub_args); diff --git a/apps/app_sms.c b/apps/app_sms.c index 0a20c8b2314f7b47029e8fe21456a71fee83fae2..6c99ad37aa56b3065e6bea66aab50cac681b2fe8 100644 --- a/apps/app_sms.c +++ b/apps/app_sms.c @@ -779,7 +779,9 @@ static void sms_log(sms_t * h, char status) } *p++ = '\n'; *p = 0; - write(o, line, strlen(line)); + if (write(o, line, strlen(line)) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } close(o); } *h->oa = *h->da = h->udl = 0; diff --git a/apps/app_stack.c b/apps/app_stack.c index 599c5f1d4b72df9f5d1c495d9e0e1ff2851c204e..714eaae2c820c91418f4c2782f8357d903d26a11 100644 --- a/apps/app_stack.c +++ b/apps/app_stack.c @@ -478,9 +478,15 @@ static int handle_gosub(struct ast_channel *chan, AGI *agi, int argc, char **arg * call a Gosub for the CALLEE channel in Dial or Queue. */ if (argc == 5) { - asprintf(&gosub_args, "%s,%s,%d(%s)", argv[1], argv[2], priority + 1, argv[4]); + if (asprintf(&gosub_args, "%s,%s,%d(%s)", argv[1], argv[2], priority + 1, argv[4]) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + gosub_args = NULL; + } } else { - asprintf(&gosub_args, "%s,%s,%d", argv[1], argv[2], priority + 1); + if (asprintf(&gosub_args, "%s,%s,%d", argv[1], argv[2], priority + 1) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + gosub_args = NULL; + } } if (gosub_args) { diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 617d31aa5506eec8f2de5a9c7ce45f046ac5abc3..de08d99b32de2312ee4e148046bd0bb3b607ebf6 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -867,7 +867,9 @@ static char *vm_check_password_shell(char *command, char *buf, size_t len) } else if (pid) { /* parent */ close(fds[1]); - read(fds[0], buf, len); + if (read(fds[0], buf, len) < 0) { + ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); + } close(fds[0]); } else { /* child */ @@ -5533,7 +5535,9 @@ static void adsi_message(struct ast_channel *chan, struct vm_state *vms) f = fopen(fn2, "r"); if (f) { while (!feof(f)) { - fgets((char *)buf, sizeof(buf), f); + if (!fgets((char *)buf, sizeof(buf), f)) { + continue; + } if (!feof(f)) { char *stringp=NULL; stringp = (char *)buf; diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index fc4863a4e172df194e2e8d56f546eaf88b626e65..a24ed5fa725098af447759c07867ecc732a1a081 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -10356,8 +10356,11 @@ static void dahdi_pri_message(struct pri *pri, char *s) ast_mutex_lock(&pridebugfdlock); - if (pridebugfd >= 0) - write(pridebugfd, s, strlen(s)); + if (pridebugfd >= 0) { + if (write(pridebugfd, s, strlen(s)) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } + } ast_mutex_unlock(&pridebugfdlock); } @@ -10392,8 +10395,11 @@ static void dahdi_pri_error(struct pri *pri, char *s) ast_mutex_lock(&pridebugfdlock); - if (pridebugfd >= 0) - write(pridebugfd, s, strlen(s)); + if (pridebugfd >= 0) { + if (write(pridebugfd, s, strlen(s)) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } + } ast_mutex_unlock(&pridebugfdlock); } diff --git a/channels/chan_h323.c b/channels/chan_h323.c index c2aaa2a6cc51cbb8ac8faa81806a2a6a98abcab1..cd6ca8e5f2e7e256e78fdfbd442367c67661b4be 100644 --- a/channels/chan_h323.c +++ b/channels/chan_h323.c @@ -1246,7 +1246,7 @@ static struct oh323_alias *realtime_alias(const char *alias) static int update_common_options(struct ast_variable *v, struct call_options *options) { - int tmp; + int tmp = 0; char *val, *opt; if (!strcasecmp(v->name, "allow")) { diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index adf4fa6f4ff1c19fa05284f3d48465dbce614211..3851d8ead99c9266053b39166c3802ac0cd17687 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -6717,8 +6717,10 @@ static int complete_dpreply(struct chan_iax2_pvt *pvt, struct iax_ies *ies) } /* Wake up waiters */ for (x = 0; x < ARRAY_LEN(dp->waiters); x++) { - if (dp->waiters[x] > -1) - write(dp->waiters[x], "asdf", 4); + if (dp->waiters[x] > -1) { + if (write(dp->waiters[x], "asdf", 4) < 0) { + } + } } } AST_LIST_TRAVERSE_SAFE_END; @@ -11782,8 +11784,11 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat systems without leaving it unavailable once the server comes back online */ dp->expiry.tv_sec = dp->orig.tv_sec + 60; for (x = 0; x < ARRAY_LEN(dp->waiters); x++) { - if (dp->waiters[x] > -1) - write(dp->waiters[x], "asdf", 4); + if (dp->waiters[x] > -1) { + if (write(dp->waiters[x], "asdf", 4) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } + } } } } diff --git a/channels/chan_oss.c b/channels/chan_oss.c index ddaa2efdecf74822f1bea13648b93b71006015f5..186e3a2a64933bc6388be1395dd434c05dc8eba5 100644 --- a/channels/chan_oss.c +++ b/channels/chan_oss.c @@ -1382,10 +1382,15 @@ static struct chan_oss_pvt *store_config(struct ast_config *cfg, char *ctg) if (o->mixer_cmd) { char *cmd; - asprintf(&cmd, "mixer %s", o->mixer_cmd); - ast_log(LOG_WARNING, "running [%s]\n", cmd); - system(cmd); - ast_free(cmd); + if (asprintf(&cmd, "mixer %s", o->mixer_cmd) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + } else { + ast_log(LOG_WARNING, "running [%s]\n", cmd); + if (system(cmd) < 0) { + ast_log(LOG_WARNING, "system() failed: %s\n", strerror(errno)); + } + ast_free(cmd); + } } /* if the config file requested to start the GUI, do it */ diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 5d04495d117bf4140a3a33378b2d98f735082d21..d1cb709fd0eef824f4a023a5a10ac85c8f60c2fd 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -22076,8 +22076,9 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str if (!ast_strlen_zero(callback)) { /* build string from peer info */ char *reg_string; - asprintf(®_string, "%s:%s@%s/%s", peer->username, peer->secret, peer->tohost, callback); - if (reg_string) { + if (asprintf(®_string, "%s:%s@%s/%s", peer->username, peer->secret, peer->tohost, callback) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + } else if (reg_string) { sip_register(reg_string, 0); /* XXX TODO: count in registry_count */ ast_free(reg_string); } diff --git a/formats/format_gsm.c b/formats/format_gsm.c index 3506f563e1b1371c8c5795868bfc18f6f35a300f..571fed8e151063689fd13a36b1d48618191e341b 100644 --- a/formats/format_gsm.c +++ b/formats/format_gsm.c @@ -126,7 +126,9 @@ static int gsm_seek(struct ast_filestream *fs, off_t sample_offset, int whence) int i; fseeko(fs->f, 0, SEEK_END); for (i=0; i< (offset - max) / GSM_FRAME_SIZE; i++) { - fwrite(gsm_silence, 1, GSM_FRAME_SIZE, fs->f); + if (!fwrite(gsm_silence, 1, GSM_FRAME_SIZE, fs->f)) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } } } return fseeko(fs->f, offset, SEEK_SET); diff --git a/formats/format_ogg_vorbis.c b/formats/format_ogg_vorbis.c index de2a20c745ccc21f4b9896444bf91352e747bb20..e3b81eff131e0bf4efc546163dd4574880384a82 100644 --- a/formats/format_ogg_vorbis.c +++ b/formats/format_ogg_vorbis.c @@ -225,8 +225,12 @@ static int ogg_vorbis_rewrite(struct ast_filestream *s, while (!tmp->eos) { if (ogg_stream_flush(&tmp->os, &tmp->og) == 0) break; - fwrite(tmp->og.header, 1, tmp->og.header_len, s->f); - fwrite(tmp->og.body, 1, tmp->og.body_len, s->f); + if (!fwrite(tmp->og.header, 1, tmp->og.header_len, s->f)) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } + if (!fwrite(tmp->og.body, 1, tmp->og.body_len, s->f)) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } if (ogg_page_eos(&tmp->og)) tmp->eos = 1; } @@ -251,8 +255,12 @@ static void write_stream(struct vorbis_desc *s, FILE *f) if (ogg_stream_pageout(&s->os, &s->og) == 0) { break; } - fwrite(s->og.header, 1, s->og.header_len, f); - fwrite(s->og.body, 1, s->og.body_len, f); + if (!fwrite(s->og.header, 1, s->og.header_len, f)) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } + if (!fwrite(s->og.body, 1, s->og.body_len, f)) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } if (ogg_page_eos(&s->og)) { s->eos = 1; } diff --git a/formats/format_wav.c b/formats/format_wav.c index 5cf39ce9938eb7183f50c5812e39a58ad0acc98d..3a629df7115c51f47367f0b241c71e792049f07e 100644 --- a/formats/format_wav.c +++ b/formats/format_wav.c @@ -334,8 +334,11 @@ static void wav_close(struct ast_filestream *s) } /* Pad to even length */ - if (fs->bytes & 0x1) - fwrite(&zero, 1, 1, s->f); + if (fs->bytes & 0x1) { + if (!fwrite(&zero, 1, 1, s->f)) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } + } } static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext) diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c index 4c3694cda0006bf1a2d087c4dee8404462bf9951..81fbded4b368489b9b7cf6642dcebb4d7b7773d4 100644 --- a/formats/format_wav_gsm.c +++ b/formats/format_wav_gsm.c @@ -496,7 +496,9 @@ static int wav_seek(struct ast_filestream *fs, off_t sample_offset, int whence) int i; fseek(fs->f, 0, SEEK_END); for (i=0; i< (offset - max) / MSGSM_FRAME_SIZE; i++) { - fwrite(msgsm_silence, 1, MSGSM_FRAME_SIZE, fs->f); + if (!fwrite(msgsm_silence, 1, MSGSM_FRAME_SIZE, fs->f)) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } } } s->secondhalf = 0; diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c index 135dd9819603a97a4e4132b16c73c85939e30d4c..c2df452ea276b3c12014ae3cb4c1ef0ba8ed536e 100644 --- a/funcs/func_odbc.c +++ b/funcs/func_odbc.c @@ -825,9 +825,13 @@ static int init_acf_query(struct ast_config *cfg, char *catg, struct acf_odbc_qu } if ((tmp = ast_variable_retrieve(cfg, catg, "prefix")) && !ast_strlen_zero(tmp)) { - asprintf((char **)&((*query)->acf->name), "%s_%s", tmp, catg); + if (asprintf((char **)&((*query)->acf->name), "%s_%s", tmp, catg) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + } } else { - asprintf((char **)&((*query)->acf->name), "ODBC_%s", catg); + if (asprintf((char **)&((*query)->acf->name), "ODBC_%s", catg) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + } } if (!((*query)->acf->name)) { diff --git a/main/ast_expr2f.c b/main/ast_expr2f.c index b6ab64e2675b4e205e3bb956ac663d8179e12876..5999c73dc758a467a7c8da11a33e0455a6e9054c 100644 --- a/main/ast_expr2f.c +++ b/main/ast_expr2f.c @@ -11,7 +11,7 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 33 +#define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -33,7 +33,7 @@ /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ -#if !defined __STDC_VERSION__ || __STDC_VERSION__ >= 199901L +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, * if you want the limit (max/min) macros for int types. @@ -56,7 +56,6 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -87,6 +86,8 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif +#endif /* ! C99 */ + #endif /* ! FLEXINT_H */ #ifdef __cplusplus @@ -96,11 +97,12 @@ typedef unsigned int flex_uint32_t; #else /* ! __cplusplus */ -#if __STDC__ +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) #define YY_USE_CONST -#endif /* __STDC__ */ +#endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ #ifdef YY_USE_CONST @@ -136,8 +138,6 @@ typedef void* yyscan_t; #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) #define yy_flex_debug yyg->yy_flex_debug_r -int ast_yylex_init (yyscan_t* scanner); - /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. @@ -195,14 +195,9 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ - #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T -typedef unsigned int yy_size_t; +typedef size_t yy_size_t; #endif #ifndef YY_STRUCT_YY_BUFFER_STATE @@ -2406,7 +2401,7 @@ int ast_yyget_column(yyscan_t yyscanner); static int curlycount = 0; static char *expr2_token_subst(const char *mess); -#line 2410 "ast_expr2f.c" +#line 2403 "ast_expr2f.c" #define INITIAL 0 #define var 1 @@ -2470,6 +2465,10 @@ static int yy_init_globals (yyscan_t yyscanner ); # define yylloc yyg->yylloc_r +int ast_yylex_init (yyscan_t* scanner); + +int ast_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); + /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ @@ -2549,7 +2548,7 @@ static int input (yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -2629,10 +2628,10 @@ YY_DECL register int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 127 "ast_expr2.fl" +#line 125 "ast_expr2.fl" -#line 2636 "ast_expr2f.c" +#line 2633 "ast_expr2f.c" yylval = yylval_param; @@ -2715,132 +2714,132 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 129 "ast_expr2.fl" +#line 127 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_OR;} YY_BREAK case 2: YY_RULE_SETUP -#line 130 "ast_expr2.fl" +#line 128 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_AND;} YY_BREAK case 3: YY_RULE_SETUP -#line 131 "ast_expr2.fl" +#line 129 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_EQ;} YY_BREAK case 4: YY_RULE_SETUP -#line 132 "ast_expr2.fl" +#line 130 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_OR;} YY_BREAK case 5: YY_RULE_SETUP -#line 133 "ast_expr2.fl" +#line 131 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_AND;} YY_BREAK case 6: YY_RULE_SETUP -#line 134 "ast_expr2.fl" +#line 132 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_EQ;} YY_BREAK case 7: YY_RULE_SETUP -#line 135 "ast_expr2.fl" +#line 133 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_EQTILDE;} YY_BREAK case 8: YY_RULE_SETUP -#line 136 "ast_expr2.fl" +#line 134 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_TILDETILDE;} YY_BREAK case 9: YY_RULE_SETUP -#line 137 "ast_expr2.fl" +#line 135 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_GT;} YY_BREAK case 10: YY_RULE_SETUP -#line 138 "ast_expr2.fl" +#line 136 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_LT;} YY_BREAK case 11: YY_RULE_SETUP -#line 139 "ast_expr2.fl" +#line 137 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_GE;} YY_BREAK case 12: YY_RULE_SETUP -#line 140 "ast_expr2.fl" +#line 138 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_LE;} YY_BREAK case 13: YY_RULE_SETUP -#line 141 "ast_expr2.fl" +#line 139 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_NE;} YY_BREAK case 14: YY_RULE_SETUP -#line 142 "ast_expr2.fl" +#line 140 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_PLUS;} YY_BREAK case 15: YY_RULE_SETUP -#line 143 "ast_expr2.fl" +#line 141 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_COMMA;} YY_BREAK case 16: YY_RULE_SETUP -#line 144 "ast_expr2.fl" +#line 142 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_MINUS;} YY_BREAK case 17: YY_RULE_SETUP -#line 145 "ast_expr2.fl" +#line 143 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_MULT;} YY_BREAK case 18: YY_RULE_SETUP -#line 146 "ast_expr2.fl" +#line 144 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_DIV;} YY_BREAK case 19: YY_RULE_SETUP -#line 147 "ast_expr2.fl" +#line 145 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_MOD;} YY_BREAK case 20: YY_RULE_SETUP -#line 148 "ast_expr2.fl" +#line 146 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_COND;} YY_BREAK case 21: YY_RULE_SETUP -#line 149 "ast_expr2.fl" +#line 147 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_COMPL;} YY_BREAK case 22: YY_RULE_SETUP -#line 150 "ast_expr2.fl" +#line 148 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_COLON;} YY_BREAK case 23: YY_RULE_SETUP -#line 151 "ast_expr2.fl" +#line 149 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_COLONCOLON;} YY_BREAK case 24: YY_RULE_SETUP -#line 152 "ast_expr2.fl" +#line 150 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_LP;} YY_BREAK case 25: YY_RULE_SETUP -#line 153 "ast_expr2.fl" +#line 151 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; return TOK_RP;} YY_BREAK case 26: YY_RULE_SETUP -#line 154 "ast_expr2.fl" +#line 152 "ast_expr2.fl" { /* gather the contents of ${} expressions, with trailing stuff, * into a single TOKEN. @@ -2853,24 +2852,24 @@ YY_RULE_SETUP YY_BREAK case 27: YY_RULE_SETUP -#line 164 "ast_expr2.fl" +#line 162 "ast_expr2.fl" {} YY_BREAK case 28: /* rule 28 can match eol */ YY_RULE_SETUP -#line 165 "ast_expr2.fl" +#line 163 "ast_expr2.fl" {SET_COLUMNS; SET_STRING; return TOKEN;} YY_BREAK case 29: /* rule 29 can match eol */ YY_RULE_SETUP -#line 167 "ast_expr2.fl" +#line 165 "ast_expr2.fl" {/* what to do with eol */} YY_BREAK case 30: YY_RULE_SETUP -#line 168 "ast_expr2.fl" +#line 166 "ast_expr2.fl" { SET_COLUMNS; /* the original behavior of the expression parser was @@ -2883,7 +2882,7 @@ YY_RULE_SETUP case 31: /* rule 31 can match eol */ YY_RULE_SETUP -#line 177 "ast_expr2.fl" +#line 175 "ast_expr2.fl" { SET_COLUMNS; SET_STRING; @@ -2893,7 +2892,7 @@ YY_RULE_SETUP case 32: /* rule 32 can match eol */ YY_RULE_SETUP -#line 184 "ast_expr2.fl" +#line 182 "ast_expr2.fl" { curlycount--; if (curlycount < 0) { @@ -2907,7 +2906,7 @@ YY_RULE_SETUP case 33: /* rule 33 can match eol */ YY_RULE_SETUP -#line 194 "ast_expr2.fl" +#line 192 "ast_expr2.fl" { curlycount++; yymore(); @@ -2915,7 +2914,7 @@ YY_RULE_SETUP YY_BREAK case 34: YY_RULE_SETUP -#line 200 "ast_expr2.fl" +#line 198 "ast_expr2.fl" { BEGIN(0); SET_COLUMNS; @@ -2926,7 +2925,7 @@ YY_RULE_SETUP case 35: /* rule 35 can match eol */ YY_RULE_SETUP -#line 207 "ast_expr2.fl" +#line 205 "ast_expr2.fl" { char c = yytext[yyleng-1]; BEGIN(0); @@ -2938,7 +2937,7 @@ YY_RULE_SETUP YY_BREAK case 36: YY_RULE_SETUP -#line 216 "ast_expr2.fl" +#line 214 "ast_expr2.fl" { curlycount = 0; BEGIN(var); @@ -2946,7 +2945,7 @@ YY_RULE_SETUP } YY_BREAK case YY_STATE_EOF(trail): -#line 222 "ast_expr2.fl" +#line 220 "ast_expr2.fl" { BEGIN(0); SET_COLUMNS; @@ -2957,10 +2956,10 @@ case YY_STATE_EOF(trail): YY_BREAK case 37: YY_RULE_SETUP -#line 230 "ast_expr2.fl" +#line 228 "ast_expr2.fl" ECHO; YY_BREAK -#line 2964 "ast_expr2f.c" +#line 2961 "ast_expr2f.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(var): yyterminate(); @@ -3217,6 +3216,14 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else ret_val = EOB_ACT_CONTINUE_SCAN; + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) ast_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + yyg->yy_n_chars += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; @@ -3640,7 +3647,9 @@ static void ast_yyensure_buffer_stack (yyscan_t yyscanner) yyg->yy_buffer_stack = (struct yy_buffer_state**)ast_yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); - + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in ast_yyensure_buffer_stack()" ); + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); yyg->yy_buffer_stack_max = num_to_alloc; @@ -3658,6 +3667,8 @@ static void ast_yyensure_buffer_stack (yyscan_t yyscanner) (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in ast_yyensure_buffer_stack()" ); /* zero only the new slots.*/ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); @@ -3976,6 +3987,42 @@ int ast_yylex_init(yyscan_t* ptr_yy_globals) return yy_init_globals ( *ptr_yy_globals ); } +/* ast_yylex_init_extra has the same functionality as ast_yylex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to ast_yyalloc in + * the yyextra field. + */ + +int ast_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) + +{ + struct yyguts_t dummy_yyguts; + + ast_yyset_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) ast_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + ast_yyset_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + static int yy_init_globals (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; @@ -4082,7 +4129,7 @@ void *ast_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 230 "ast_expr2.fl" +#line 228 "ast_expr2.fl" diff --git a/main/asterisk.c b/main/asterisk.c index 239acd7ffd07e45fa6fef16744c94408c9ad2923..37c84bd6704309189ec3ccb03433c009ce12861a 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -1218,8 +1218,11 @@ static void hup_handler(int num) if (restartnow) execvp(_argv[0], _argv); sig_flags.need_reload = 1; - if (sig_alert_pipe[1] != -1) - write(sig_alert_pipe[1], &a, sizeof(a)); + if (sig_alert_pipe[1] != -1) { + if (write(sig_alert_pipe[1], &a, sizeof(a)) < 0) { + fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno)); + } + } signal(num, hup_handler); } @@ -1434,8 +1437,11 @@ static void __quit_handler(int num) { int a = 0; sig_flags.need_quit = 1; - if (sig_alert_pipe[1] != -1) - write(sig_alert_pipe[1], &a, sizeof(a)); + if (sig_alert_pipe[1] != -1) { + if (write(sig_alert_pipe[1], &a, sizeof(a)) < 0) { + fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno)); + } + } /* There is no need to restore the signal handler here, since the app * is going to exit */ } @@ -1814,7 +1820,7 @@ static char *show_warranty(struct ast_cli_entry *e, int cmd, struct ast_cli_args return NULL; } - ast_cli(a->fd, warranty_lines); + ast_cli(a->fd, "%s", warranty_lines); return CLI_SUCCESS; } @@ -1851,7 +1857,7 @@ static char *show_license(struct ast_cli_entry *e, int cmd, struct ast_cli_args return NULL; } - ast_cli(a->fd, license_lines); + ast_cli(a->fd, "%s", license_lines); return CLI_SUCCESS; } @@ -1971,9 +1977,12 @@ static int ast_el_read_char(EditLine *editline, char *cp) } /* Write over the CLI prompt */ - if (!ast_opt_exec && !lastpos) - write(STDOUT_FILENO, "\r", 1); - write(STDOUT_FILENO, buf, res); + if (!ast_opt_exec && !lastpos) { + if (write(STDOUT_FILENO, "\r", 1) < 0) { + } + } + if (write(STDOUT_FILENO, buf, res) < 0) { + } if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (buf[res-2] == '\n'))) { *cp = CC_REFRESH; return(1); @@ -2416,7 +2425,7 @@ static int ast_el_read_history(char *filename) return ret; } -static void ast_remotecontrol(char * data) +static void ast_remotecontrol(char *data) { char buf[80]; int res; @@ -2430,12 +2439,17 @@ static void ast_remotecontrol(char * data) char *ebuf; int num = 0; - read(ast_consock, buf, sizeof(buf)); + if (read(ast_consock, buf, sizeof(buf)) < 0) { + ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno)); + return; + } if (data) { char prefix[] = "cli quit after "; char *tmp = alloca(strlen(data) + strlen(prefix) + 1); sprintf(tmp, "%s%s", prefix, data); - write(ast_consock, tmp, strlen(tmp) + 1); + if (write(ast_consock, tmp, strlen(tmp) + 1) < 0) { + ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno)); + } } stringp = buf; hostname = strsep(&stringp, "/"); @@ -2495,7 +2509,9 @@ static void ast_remotecontrol(char * data) /* Skip verbose lines */ if (*curline != 127) { not_written = 0; - write(STDOUT_FILENO, curline, nextline - curline); + if (write(STDOUT_FILENO, curline, nextline - curline) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } } curline = nextline; } while (!ast_strlen_zero(curline)); @@ -2825,7 +2841,8 @@ static void *monitor_sig_flags(void *unused) sig_flags.need_quit = 0; quit_handler(0, 0, 1, 0); } - read(sig_alert_pipe[0], &a, sizeof(a)); + if (read(sig_alert_pipe[0], &a, sizeof(a)) != sizeof(a)) { + } } return NULL; @@ -3265,7 +3282,9 @@ int main(int argc, char *argv[]) #if HAVE_WORKING_FORK if (ast_opt_always_fork || !ast_opt_no_fork) { #ifndef HAVE_SBIN_LAUNCHD - daemon(1, 0); + if (daemon(1, 0) < 0) { + ast_log(LOG_ERROR, "daemon() failed: %s\n", strerror(errno)); + } ast_mainpid = getpid(); /* Blindly re-write pid file since we are forking */ unlink(ast_config_AST_PID); diff --git a/main/channel.c b/main/channel.c index 6ace4c008efc63e67836f303ebd6b13991f72ff4..4174613ec4e7bf2fa27ea86e4fa44205d9e9923a 100644 --- a/main/channel.c +++ b/main/channel.c @@ -2272,8 +2272,11 @@ int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int cmdfd) break; case AST_FRAME_VOICE: /* Write audio if appropriate */ - if (audiofd > -1) - write(audiofd, f->data.ptr, f->datalen); + if (audiofd > -1) { + if (write(audiofd, f->data.ptr, f->datalen) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } + } default: /* Ignore */ break; @@ -2420,7 +2423,9 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio) goto done; } } - read(chan->alertpipe[0], &blah, sizeof(blah)); + if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) { + ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); + } } if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD) { @@ -3887,7 +3892,10 @@ int ast_do_masquerade(struct ast_channel *original) AST_LIST_INSERT_TAIL(&original->readq, current, frame_list); if (original->alertpipe[1] > -1) { int poke = 0; - write(original->alertpipe[1], &poke, sizeof(poke)); + + if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } } } } diff --git a/main/db1-ast/hash/hash_page.c b/main/db1-ast/hash/hash_page.c index 737b97d32187e83ad72d622718014ca83f32fb32..52571c5521cb1c77ce4a1b8febd98e321e938954 100644 --- a/main/db1-ast/hash/hash_page.c +++ b/main/db1-ast/hash/hash_page.c @@ -712,7 +712,8 @@ overflow_page(hashp) #define OVMSG "HASH: Out of overflow pages. Increase page size\n" if (offset > SPLITMASK) { if (++splitnum >= NCACHED) { - (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); + if (write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1) < 0) { + } return (0); } hashp->OVFL_POINT = splitnum; @@ -725,7 +726,8 @@ overflow_page(hashp) if (free_bit == (hashp->BSIZE << BYTE_SHIFT) - 1) { free_page++; if (free_page >= NCACHED) { - (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); + if (write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1) < 0) { + } return (0); } /* @@ -749,8 +751,8 @@ overflow_page(hashp) offset++; if (offset > SPLITMASK) { if (++splitnum >= NCACHED) { - (void)write(STDERR_FILENO, OVMSG, - sizeof(OVMSG) - 1); + if (write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1) < 0) { + } return (0); } hashp->OVFL_POINT = splitnum; diff --git a/main/file.c b/main/file.c index a9b36e7f5dd9c1fed797e1661b0d7a2b48885ca7..f6bdd7cf519ddd9b804f067abab65b1018adb29b 100644 --- a/main/file.c +++ b/main/file.c @@ -249,11 +249,18 @@ static char *build_filename(const char *filename, const char *ext) if (!strcmp(ext, "wav49")) ext = "WAV"; - if (filename[0] == '/') - asprintf(&fn, "%s.%s", filename, ext); - else - asprintf(&fn, "%s/sounds/%s.%s", - ast_config_AST_DATA_DIR, filename, ext); + if (filename[0] == '/') { + if (asprintf(&fn, "%s.%s", filename, ext) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + fn = NULL; + } + } else { + if (asprintf(&fn, "%s/sounds/%s.%s", + ast_config_AST_DATA_DIR, filename, ext) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + fn = NULL; + } + } return fn; } @@ -1187,8 +1194,11 @@ static int waitstream_core(struct ast_channel *c, const char *breakon, break; case AST_FRAME_VOICE: /* Write audio if appropriate */ - if (audiofd > -1) - write(audiofd, fr->data.ptr, fr->datalen); + if (audiofd > -1) { + if (write(audiofd, fr->data.ptr, fr->datalen) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } + } default: /* Ignore all others */ break; diff --git a/main/http.c b/main/http.c index f7a1e18a0838d231cc64c249ccd8fa193cd9d8ad..0e59146a48ac7f62ebc4d3dccf47a2554ed43531 100644 --- a/main/http.c +++ b/main/http.c @@ -219,7 +219,9 @@ static struct ast_str *static_callback(struct ast_tcptls_session_instance *ser, ast_get_version(), buf, (int) st.st_size, mtype); while ((len = read(fd, buf, sizeof(buf))) > 0) { - fwrite(buf, 1, len, ser->f); + if (fwrite(buf, 1, len, ser->f) != len) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } } close(fd); @@ -760,8 +762,12 @@ static void *httpd_helper_thread(void *data) if (tmp) { fprintf(ser->f, "Content-length: %d\r\n", contentlength); /* first write the header, then the body */ - fwrite(out->str, 1, (tmp + 4 - out->str), ser->f); - fwrite(tmp + 4, 1, contentlength, ser->f); + if (fwrite(out->str, 1, (tmp + 4 - out->str), ser->f) != tmp + 4 - out->str) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } + if (fwrite(tmp + 4, 1, contentlength, ser->f) != contentlength ) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } } } ast_free(out); diff --git a/main/logger.c b/main/logger.c index d09d8271f63392183c9cea43ba8b3bed667fdcaf..4e3a2b73caf09f66f5524d9010dd4f34e77220fa 100644 --- a/main/logger.c +++ b/main/logger.c @@ -576,7 +576,9 @@ static int rotate_file(const char *filename) char buf[512]; pbx_builtin_setvar_helper(c, "filename", filename); pbx_substitute_variables_helper(c, exec_after_rotate, buf, sizeof(buf)); - system(buf); + if (system(buf) < 0) { + ast_log(LOG_WARNING, "system() failed for '%s': %s\n", buf, strerror(errno)); + } ast_channel_free(c); } return res; diff --git a/main/manager.c b/main/manager.c index 71e97b8f9d5a82acd0d68a6cd7c0c86227b8f420..e7fd926f0e0a9a700a9b9500a2a8d9ad27cc6c34 100644 --- a/main/manager.c +++ b/main/manager.c @@ -2212,7 +2212,9 @@ static int action_command(struct mansession *s, const struct message *m) final_buf = ast_calloc(1, l + 1); if (buf) { lseek(fd, 0, SEEK_SET); - read(fd, buf, l); + if (read(fd, buf, l) < 0) { + ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); + } buf[l] = '\0'; if (final_buf) { term_strip(final_buf, buf, l); diff --git a/main/utils.c b/main/utils.c index eff270fba0b1b37109b31a8c6c5970a298212a64..9a7a3acd4556252fa2f87ea4ce9bdcbc28d4638c 100644 --- a/main/utils.c +++ b/main/utils.c @@ -1066,8 +1066,11 @@ int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*st a->start_routine = start_routine; a->data = data; start_routine = dummy_start; - asprintf(&a->name, "%-20s started at [%5d] %s %s()", - start_fn, line, file, caller); + if (asprintf(&a->name, "%-20s started at [%5d] %s %s()", + start_fn, line, file, caller) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + a->name = NULL; + } data = a; } #endif /* !LOW_MEMORY */ diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c index 2899ec1a7164181292a8f2ec79607466053bf31f..84fa564ae816593b813b8af56f8c89522252a0d9 100644 --- a/pbx/pbx_config.c +++ b/pbx/pbx_config.c @@ -492,10 +492,16 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a) if (++which > a->n) { /* If there is an extension then return exten@context. */ if (ast_get_extension_matchcid(e) && (!strchr(a->word, '@') || strchr(a->word, '/'))) { - asprintf(&ret, "%s/%s@%s", ast_get_extension_name(e), ast_get_extension_cidmatch(e), ast_get_context_name(c)); + if (asprintf(&ret, "%s/%s@%s", ast_get_extension_name(e), ast_get_extension_cidmatch(e), ast_get_context_name(c)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + ret = NULL; + } break; } else if (!ast_get_extension_matchcid(e) && !strchr(a->word, '/')) { - asprintf(&ret, "%s@%s", ast_get_extension_name(e), ast_get_context_name(c)); + if (asprintf(&ret, "%s@%s", ast_get_extension_name(e), ast_get_context_name(c)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + ret = NULL; + } break; } } diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c index 5d3a0be12d8ebdb012a9c00eba4fdd3bd4206dcd..12ab1328d04c3851412224175af36737fbc91369 100644 --- a/pbx/pbx_dundi.c +++ b/pbx/pbx_dundi.c @@ -2958,7 +2958,9 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout) if (AST_LIST_EMPTY(&trans->parent->trans)) { /* Wake up sleeper */ if (trans->parent->pfds[1] > -1) { - write(trans->parent->pfds[1], "killa!", 6); + if (write(trans->parent->pfds[1], "killa!", 6) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + } } } } @@ -3725,7 +3727,10 @@ static int dundi_precache_internal(const char *context, const char *number, int dr.expiration = dundi_cache_time; dr.hmd = &hmd; dr.pfds[0] = dr.pfds[1] = -1; - pipe(dr.pfds); + if (pipe(dr.pfds) < 0) { + ast_log(LOG_WARNING, "pipe() failed: %s\n", strerror(errno)); + return -1; + } build_transactions(&dr, ttl, 0, &foundcache, &skipped, 0, 1, 1, NULL, avoids, NULL); optimize_transactions(&dr, 0); foundanswers = 0; diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c index ba6a7c45626e1f137432594b18cb96e5ed61dbaa..7bc1a8ad1c9db58ffddab67d4f448e9b48362c84 100644 --- a/pbx/pbx_lua.c +++ b/pbx/pbx_lua.c @@ -946,7 +946,9 @@ static char *lua_read_extensions_file(lua_State *L, long *size) return NULL; } - fread(data, sizeof(char), *size, f); + if (fread(data, sizeof(char), *size, f) != *size) { + ast_log(LOG_WARNING, "fread() failed: %s\n", strerror(errno)); + } fclose(f); if (luaL_loadbuffer(L, data, *size, "extensions.lua") diff --git a/res/ael/ael.flex b/res/ael/ael.flex index 64c96a64902b2ffef404a51cd8cecc00c766630b..4b29b5a6b17bce765fed2437937e980fffeea950 100644 --- a/res/ael/ael.flex +++ b/res/ael/ael.flex @@ -773,7 +773,9 @@ struct pval *ael2_parse(char *filename, int *errors) my_file = strdup(filename); stat(filename, &stats); buffer = (char*)malloc(stats.st_size+2); - fread(buffer, 1, stats.st_size, fin); + if (fread(buffer, 1, stats.st_size, fin) != stats.st_size) { + ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno)); + } buffer[stats.st_size]=0; fclose(fin); @@ -841,7 +843,9 @@ static void setup_filestack(char *fnamebuf2, int fnamebuf_siz, glob_t *globbuf, struct stat stats; stat(fnamebuf2, &stats); buffer = (char*)malloc(stats.st_size+1); - fread(buffer, 1, stats.st_size, in1); + if (fread(buffer, 1, stats.st_size, in1) != stats.st_size) { + ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno)); + } buffer[stats.st_size] = 0; ast_log(LOG_NOTICE," --Read in included file %s, %d chars\n",fnamebuf2, (int)stats.st_size); fclose(in1); diff --git a/res/ael/ael.tab.c b/res/ael/ael.tab.c index bebecf6c225b2a40fa908f5cf9f6faca0d26dd93..b24ee1c1a04ec523fe84a164a37281987be79d1d 100644 --- a/res/ael/ael.tab.c +++ b/res/ael/ael.tab.c @@ -647,16 +647,16 @@ static const yytype_uint16 yyrline[] = 237, 238, 239, 242, 242, 248, 248, 255, 256, 257, 258, 261, 262, 263, 266, 267, 268, 269, 270, 271, 272, 273, 274, 277, 282, 286, 294, 299, 304, 313, - 314, 315, 321, 326, 330, 338, 338, 342, 345, 348, - 359, 360, 367, 368, 372, 376, 382, 383, 388, 396, - 397, 401, 407, 416, 419, 420, 421, 424, 427, 430, - 431, 432, 430, 438, 442, 443, 444, 445, 448, 448, - 481, 482, 483, 484, 488, 491, 492, 495, 496, 499, - 502, 506, 510, 514, 520, 521, 525, 528, 534, 534, - 539, 547, 547, 558, 565, 568, 569, 572, 573, 576, - 579, 580, 583, 587, 591, 597, 598, 601, 602, 603, - 609, 614, 619, 620, 621, 623, 626, 627, 634, 635, - 636, 639, 642 + 314, 315, 321, 331, 335, 343, 343, 347, 350, 353, + 364, 365, 377, 378, 387, 396, 407, 408, 418, 431, + 432, 441, 452, 461, 464, 465, 466, 469, 472, 475, + 476, 477, 475, 483, 487, 488, 489, 490, 493, 493, + 526, 527, 528, 529, 533, 536, 537, 540, 541, 544, + 547, 551, 555, 559, 565, 566, 570, 573, 579, 579, + 584, 592, 592, 603, 610, 613, 614, 617, 618, 621, + 624, 625, 628, 632, 636, 642, 643, 646, 647, 648, + 654, 659, 664, 665, 666, 677, 680, 681, 688, 689, + 690, 693, 696 }; #endif @@ -2406,19 +2406,24 @@ yyreduce: case 52: #line 321 "ael.y" { - asprintf(&(yyval.str), "%s:%s:%s", (yyvsp[(1) - (5)].str), (yyvsp[(3) - (5)].str), (yyvsp[(5) - (5)].str)); - free((yyvsp[(1) - (5)].str)); - free((yyvsp[(3) - (5)].str)); - free((yyvsp[(5) - (5)].str)); ;} + if (asprintf(&(yyval.str), "%s:%s:%s", (yyvsp[(1) - (5)].str), (yyvsp[(3) - (5)].str), (yyvsp[(5) - (5)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (5)].str)); + free((yyvsp[(3) - (5)].str)); + free((yyvsp[(5) - (5)].str)); + } + ;} break; case 53: -#line 326 "ael.y" +#line 331 "ael.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; case 54: -#line 330 "ael.y" +#line 335 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (7)].str), &(yylsp[(1) - (7)])); (yyval.pval)->next = nword((yyvsp[(3) - (7)].str), &(yylsp[(3) - (7)])); @@ -2427,31 +2432,31 @@ yyreduce: break; case 55: -#line 338 "ael.y" +#line 343 "ael.y" { reset_parencount(parseio->scanner); ;} break; case 56: -#line 338 "ael.y" +#line 343 "ael.y" { (yyval.str) = (yyvsp[(3) - (4)].str); ;} break; case 57: -#line 342 "ael.y" +#line 347 "ael.y" { (yyval.pval)= npval2(PV_IF, &(yylsp[(1) - (2)]), &(yylsp[(2) - (2)])); (yyval.pval)->u1.str = (yyvsp[(2) - (2)].str); ;} break; case 58: -#line 345 "ael.y" +#line 350 "ael.y" { (yyval.pval) = npval2(PV_RANDOM, &(yylsp[(1) - (2)]), &(yylsp[(2) - (2)])); (yyval.pval)->u1.str=(yyvsp[(2) - (2)].str);;} break; case 59: -#line 348 "ael.y" +#line 353 "ael.y" { (yyval.pval) = npval2(PV_IFTIME, &(yylsp[(1) - (4)]), &(yylsp[(4) - (4)])); (yyval.pval)->u1.list = (yyvsp[(3) - (4)].pval); @@ -2459,95 +2464,135 @@ yyreduce: break; case 60: -#line 359 "ael.y" +#line 364 "ael.y" { (yyval.str) = (yyvsp[(1) - (1)].str);;} break; case 61: -#line 360 "ael.y" +#line 365 "ael.y" { - asprintf(&((yyval.str)), "%s%s", (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str)); - free((yyvsp[(1) - (2)].str)); - free((yyvsp[(2) - (2)].str)); - prev_word = (yyval.str);;} + if (asprintf(&((yyval.str)), "%s%s", (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (2)].str)); + free((yyvsp[(2) - (2)].str)); + prev_word = (yyval.str); + } + ;} break; case 62: -#line 367 "ael.y" +#line 377 "ael.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; case 63: -#line 368 "ael.y" +#line 378 "ael.y" { - asprintf(&((yyval.str)), "%s %s", (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str)); - free((yyvsp[(1) - (2)].str)); - free((yyvsp[(2) - (2)].str)); ;} + if (asprintf(&((yyval.str)), "%s %s", (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (2)].str)); + free((yyvsp[(2) - (2)].str)); + } + ;} break; case 64: -#line 372 "ael.y" +#line 387 "ael.y" { - asprintf(&((yyval.str)), "%s:%s", (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str)); - free((yyvsp[(1) - (3)].str)); - free((yyvsp[(3) - (3)].str)); ;} + if (asprintf(&((yyval.str)), "%s:%s", (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (3)].str)); + free((yyvsp[(3) - (3)].str)); + } + ;} break; case 65: -#line 376 "ael.y" +#line 396 "ael.y" { /* there are often '&' in hints */ - asprintf(&((yyval.str)), "%s&%s", (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str)); - free((yyvsp[(1) - (3)].str)); - free((yyvsp[(3) - (3)].str));;} + if (asprintf(&((yyval.str)), "%s&%s", (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (3)].str)); + free((yyvsp[(3) - (3)].str)); + } + ;} break; case 66: -#line 382 "ael.y" +#line 407 "ael.y" { (yyval.str) = (yyvsp[(1) - (1)].str);;} break; case 67: -#line 383 "ael.y" +#line 408 "ael.y" { - asprintf(&((yyval.str)), "%s%s", (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str)); - free((yyvsp[(1) - (2)].str)); - free((yyvsp[(2) - (2)].str)); - prev_word = (yyval.str);;} + if (asprintf(&((yyval.str)), "%s%s", (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (2)].str)); + free((yyvsp[(2) - (2)].str)); + prev_word = (yyval.str); + } + ;} break; case 68: -#line 388 "ael.y" +#line 418 "ael.y" { - asprintf(&((yyval.str)), "%s%s%s", (yyvsp[(1) - (3)].str), (yyvsp[(2) - (3)].str), (yyvsp[(3) - (3)].str)); - free((yyvsp[(1) - (3)].str)); - free((yyvsp[(2) - (3)].str)); - free((yyvsp[(3) - (3)].str)); - prev_word=(yyval.str);;} + if (asprintf(&((yyval.str)), "%s%s%s", (yyvsp[(1) - (3)].str), (yyvsp[(2) - (3)].str), (yyvsp[(3) - (3)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (3)].str)); + free((yyvsp[(2) - (3)].str)); + free((yyvsp[(3) - (3)].str)); + prev_word=(yyval.str); + } + ;} break; case 69: -#line 396 "ael.y" +#line 431 "ael.y" { (yyval.str) = (yyvsp[(1) - (1)].str);;} break; case 70: -#line 397 "ael.y" +#line 432 "ael.y" { - asprintf(&((yyval.str)), "%s%s", (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str)); - free((yyvsp[(1) - (2)].str)); - free((yyvsp[(2) - (2)].str));;} + if (asprintf(&((yyval.str)), "%s%s", (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (2)].str)); + free((yyvsp[(2) - (2)].str)); + } + ;} break; case 71: -#line 401 "ael.y" +#line 441 "ael.y" { - asprintf(&((yyval.str)), "%s:%s", (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str)); - free((yyvsp[(1) - (3)].str)); - free((yyvsp[(3) - (3)].str));;} + if (asprintf(&((yyval.str)), "%s:%s", (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.str) = NULL; + } else { + free((yyvsp[(1) - (3)].str)); + free((yyvsp[(3) - (3)].str)); + } + ;} break; case 72: -#line 407 "ael.y" +#line 452 "ael.y" { (yyval.pval) = npval2(PV_SWITCH, &(yylsp[(1) - (5)]), &(yylsp[(5) - (5)])); (yyval.pval)->u1.str = (yyvsp[(2) - (5)].str); @@ -2555,60 +2600,60 @@ yyreduce: break; case 73: -#line 416 "ael.y" +#line 461 "ael.y" { (yyval.pval) = npval2(PV_STATEMENTBLOCK, &(yylsp[(1) - (3)]), &(yylsp[(3) - (3)])); (yyval.pval)->u1.list = (yyvsp[(2) - (3)].pval); set_dads((yyval.pval),(yyvsp[(2) - (3)].pval));;} break; case 74: -#line 419 "ael.y" +#line 464 "ael.y" { (yyval.pval) = (yyvsp[(1) - (1)].pval); ;} break; case 75: -#line 420 "ael.y" +#line 465 "ael.y" { (yyval.pval) = (yyvsp[(1) - (1)].pval); ;} break; case 76: -#line 421 "ael.y" +#line 466 "ael.y" { (yyval.pval) = npval2(PV_GOTO, &(yylsp[(1) - (3)]), &(yylsp[(3) - (3)])); (yyval.pval)->u1.list = (yyvsp[(2) - (3)].pval);;} break; case 77: -#line 424 "ael.y" +#line 469 "ael.y" { (yyval.pval) = npval2(PV_GOTO, &(yylsp[(1) - (3)]), &(yylsp[(3) - (3)])); (yyval.pval)->u1.list = (yyvsp[(2) - (3)].pval);;} break; case 78: -#line 427 "ael.y" +#line 472 "ael.y" { (yyval.pval) = npval2(PV_LABEL, &(yylsp[(1) - (2)]), &(yylsp[(2) - (2)])); (yyval.pval)->u1.str = (yyvsp[(1) - (2)].str); ;} break; case 79: -#line 430 "ael.y" +#line 475 "ael.y" {reset_semicount(parseio->scanner);;} break; case 80: -#line 431 "ael.y" +#line 476 "ael.y" {reset_semicount(parseio->scanner);;} break; case 81: -#line 432 "ael.y" +#line 477 "ael.y" {reset_parencount(parseio->scanner);;} break; case 82: -#line 432 "ael.y" +#line 477 "ael.y" { /* XXX word_list maybe ? */ (yyval.pval) = npval2(PV_FOR, &(yylsp[(1) - (12)]), &(yylsp[(12) - (12)])); (yyval.pval)->u1.for_init = (yyvsp[(4) - (12)].str); @@ -2618,7 +2663,7 @@ yyreduce: break; case 83: -#line 438 "ael.y" +#line 483 "ael.y" { (yyval.pval) = npval2(PV_WHILE, &(yylsp[(1) - (3)]), &(yylsp[(3) - (3)])); (yyval.pval)->u1.str = (yyvsp[(2) - (3)].str); @@ -2626,34 +2671,34 @@ yyreduce: break; case 84: -#line 442 "ael.y" +#line 487 "ael.y" { (yyval.pval) = (yyvsp[(1) - (1)].pval); ;} break; case 85: -#line 443 "ael.y" +#line 488 "ael.y" { (yyval.pval) = update_last((yyvsp[(2) - (3)].pval), &(yylsp[(2) - (3)])); ;} break; case 86: -#line 444 "ael.y" +#line 489 "ael.y" { (yyval.pval) = update_last((yyvsp[(1) - (2)].pval), &(yylsp[(2) - (2)])); ;} break; case 87: -#line 445 "ael.y" +#line 490 "ael.y" { (yyval.pval)= npval2(PV_APPLICATION_CALL, &(yylsp[(1) - (2)]), &(yylsp[(2) - (2)])); (yyval.pval)->u1.str = (yyvsp[(1) - (2)].str);;} break; case 88: -#line 448 "ael.y" +#line 493 "ael.y" {reset_semicount(parseio->scanner);;} break; case 89: -#line 448 "ael.y" +#line 493 "ael.y" { char *bufx; int tot=0; @@ -2690,22 +2735,22 @@ yyreduce: break; case 90: -#line 481 "ael.y" +#line 526 "ael.y" { (yyval.pval) = npval2(PV_BREAK, &(yylsp[(1) - (2)]), &(yylsp[(2) - (2)])); ;} break; case 91: -#line 482 "ael.y" +#line 527 "ael.y" { (yyval.pval) = npval2(PV_RETURN, &(yylsp[(1) - (2)]), &(yylsp[(2) - (2)])); ;} break; case 92: -#line 483 "ael.y" +#line 528 "ael.y" { (yyval.pval) = npval2(PV_CONTINUE, &(yylsp[(1) - (2)]), &(yylsp[(2) - (2)])); ;} break; case 93: -#line 484 "ael.y" +#line 529 "ael.y" { (yyval.pval) = update_last((yyvsp[(1) - (3)].pval), &(yylsp[(2) - (3)])); (yyval.pval)->u2.statements = (yyvsp[(2) - (3)].pval); set_dads((yyval.pval),(yyvsp[(2) - (3)].pval)); @@ -2713,41 +2758,41 @@ yyreduce: break; case 94: -#line 488 "ael.y" +#line 533 "ael.y" { (yyval.pval)=0; ;} break; case 95: -#line 491 "ael.y" +#line 536 "ael.y" { (yyval.pval) = (yyvsp[(2) - (2)].pval); ;} break; case 96: -#line 492 "ael.y" +#line 537 "ael.y" { (yyval.pval) = NULL ; ;} break; case 97: -#line 495 "ael.y" +#line 540 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (1)].str), &(yylsp[(1) - (1)])); ;} break; case 98: -#line 496 "ael.y" +#line 541 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (3)].str), &(yylsp[(1) - (3)])); (yyval.pval)->next = nword((yyvsp[(3) - (3)].str), &(yylsp[(3) - (3)])); ;} break; case 99: -#line 499 "ael.y" +#line 544 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (3)].str), &(yylsp[(1) - (3)])); (yyval.pval)->next = nword((yyvsp[(3) - (3)].str), &(yylsp[(3) - (3)])); ;} break; case 100: -#line 502 "ael.y" +#line 547 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (5)].str), &(yylsp[(1) - (5)])); (yyval.pval)->next = nword((yyvsp[(3) - (5)].str), &(yylsp[(3) - (5)])); @@ -2755,7 +2800,7 @@ yyreduce: break; case 101: -#line 506 "ael.y" +#line 551 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (5)].str), &(yylsp[(1) - (5)])); (yyval.pval)->next = nword((yyvsp[(3) - (5)].str), &(yylsp[(3) - (5)])); @@ -2763,7 +2808,7 @@ yyreduce: break; case 102: -#line 510 "ael.y" +#line 555 "ael.y" { (yyval.pval) = nword(strdup("default"), &(yylsp[(1) - (5)])); (yyval.pval)->next = nword((yyvsp[(3) - (5)].str), &(yylsp[(3) - (5)])); @@ -2771,7 +2816,7 @@ yyreduce: break; case 103: -#line 514 "ael.y" +#line 559 "ael.y" { (yyval.pval) = nword(strdup("default"), &(yylsp[(1) - (5)])); (yyval.pval)->next = nword((yyvsp[(3) - (5)].str), &(yylsp[(3) - (5)])); @@ -2779,24 +2824,24 @@ yyreduce: break; case 104: -#line 520 "ael.y" +#line 565 "ael.y" { (yyval.str) = strdup("1"); ;} break; case 105: -#line 521 "ael.y" +#line 566 "ael.y" { (yyval.str) = (yyvsp[(2) - (2)].str); ;} break; case 106: -#line 525 "ael.y" +#line 570 "ael.y" { /* ext[, pri] default 1 */ (yyval.pval) = nword((yyvsp[(1) - (2)].str), &(yylsp[(1) - (2)])); (yyval.pval)->next = nword((yyvsp[(2) - (2)].str), &(yylsp[(2) - (2)])); ;} break; case 107: -#line 528 "ael.y" +#line 573 "ael.y" { /* context, ext, pri */ (yyval.pval) = nword((yyvsp[(4) - (4)].str), &(yylsp[(4) - (4)])); (yyval.pval)->next = nword((yyvsp[(1) - (4)].str), &(yylsp[(1) - (4)])); @@ -2804,12 +2849,12 @@ yyreduce: break; case 108: -#line 534 "ael.y" +#line 579 "ael.y" {reset_argcount(parseio->scanner);;} break; case 109: -#line 534 "ael.y" +#line 579 "ael.y" { /* XXX original code had @2 but i think we need @5 */ (yyval.pval) = npval2(PV_MACRO_CALL, &(yylsp[(1) - (5)]), &(yylsp[(5) - (5)])); @@ -2818,19 +2863,19 @@ yyreduce: break; case 110: -#line 539 "ael.y" +#line 584 "ael.y" { (yyval.pval)= npval2(PV_MACRO_CALL, &(yylsp[(1) - (3)]), &(yylsp[(3) - (3)])); (yyval.pval)->u1.str = (yyvsp[(1) - (3)].str); ;} break; case 111: -#line 547 "ael.y" +#line 592 "ael.y" {reset_argcount(parseio->scanner);;} break; case 112: -#line 547 "ael.y" +#line 592 "ael.y" { if (strcasecmp((yyvsp[(1) - (3)].str),"goto") == 0) { (yyval.pval) = npval2(PV_GOTO, &(yylsp[(1) - (3)]), &(yylsp[(2) - (3)])); @@ -2843,7 +2888,7 @@ yyreduce: break; case 113: -#line 558 "ael.y" +#line 603 "ael.y" { (yyval.pval) = update_last((yyvsp[(1) - (3)].pval), &(yylsp[(3) - (3)])); if( (yyval.pval)->type == PV_GOTO ) @@ -2854,49 +2899,49 @@ yyreduce: break; case 114: -#line 565 "ael.y" +#line 610 "ael.y" { (yyval.pval) = update_last((yyvsp[(1) - (2)].pval), &(yylsp[(2) - (2)])); ;} break; case 115: -#line 568 "ael.y" +#line 613 "ael.y" { (yyval.str) = (yyvsp[(1) - (1)].str) ;} break; case 116: -#line 569 "ael.y" +#line 614 "ael.y" { (yyval.str) = strdup(""); ;} break; case 117: -#line 572 "ael.y" +#line 617 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (1)].str), &(yylsp[(1) - (1)])); ;} break; case 118: -#line 573 "ael.y" +#line 618 "ael.y" { (yyval.pval)= npval(PV_WORD,0/*@1.first_line*/,0/*@1.last_line*/,0/* @1.first_column*/, 0/*@1.last_column*/); (yyval.pval)->u1.str = strdup(""); ;} break; case 119: -#line 576 "ael.y" +#line 621 "ael.y" { (yyval.pval) = linku1((yyvsp[(1) - (3)].pval), nword((yyvsp[(3) - (3)].str), &(yylsp[(3) - (3)]))); ;} break; case 120: -#line 579 "ael.y" +#line 624 "ael.y" { (yyval.pval) = NULL; ;} break; case 121: -#line 580 "ael.y" +#line 625 "ael.y" { (yyval.pval) = linku1((yyvsp[(1) - (2)].pval), (yyvsp[(2) - (2)].pval)); ;} break; case 122: -#line 583 "ael.y" +#line 628 "ael.y" { (yyval.pval) = npval2(PV_CASE, &(yylsp[(1) - (4)]), &(yylsp[(3) - (4)])); /* XXX 3 or 4 ? */ (yyval.pval)->u1.str = (yyvsp[(2) - (4)].str); @@ -2904,7 +2949,7 @@ yyreduce: break; case 123: -#line 587 "ael.y" +#line 632 "ael.y" { (yyval.pval) = npval2(PV_DEFAULT, &(yylsp[(1) - (3)]), &(yylsp[(3) - (3)])); (yyval.pval)->u1.str = NULL; @@ -2912,7 +2957,7 @@ yyreduce: break; case 124: -#line 591 "ael.y" +#line 636 "ael.y" { (yyval.pval) = npval2(PV_PATTERN, &(yylsp[(1) - (4)]), &(yylsp[(4) - (4)])); /* XXX@3 or @4 ? */ (yyval.pval)->u1.str = (yyvsp[(2) - (4)].str); @@ -2920,27 +2965,27 @@ yyreduce: break; case 125: -#line 597 "ael.y" +#line 642 "ael.y" { (yyval.pval) = NULL; ;} break; case 126: -#line 598 "ael.y" +#line 643 "ael.y" { (yyval.pval) = linku1((yyvsp[(1) - (2)].pval), (yyvsp[(2) - (2)].pval)); ;} break; case 127: -#line 601 "ael.y" +#line 646 "ael.y" {(yyval.pval)=(yyvsp[(1) - (1)].pval);;} break; case 128: -#line 602 "ael.y" +#line 647 "ael.y" { (yyval.pval)=(yyvsp[(1) - (1)].pval);;} break; case 129: -#line 603 "ael.y" +#line 648 "ael.y" { (yyval.pval) = npval2(PV_CATCH, &(yylsp[(1) - (5)]), &(yylsp[(5) - (5)])); (yyval.pval)->u1.str = (yyvsp[(2) - (5)].str); @@ -2948,47 +2993,56 @@ yyreduce: break; case 130: -#line 609 "ael.y" +#line 654 "ael.y" { (yyval.pval) = npval2(PV_SWITCHES, &(yylsp[(1) - (4)]), &(yylsp[(2) - (4)])); (yyval.pval)->u1.list = (yyvsp[(3) - (4)].pval); set_dads((yyval.pval),(yyvsp[(3) - (4)].pval));;} break; case 131: -#line 614 "ael.y" +#line 659 "ael.y" { (yyval.pval) = npval2(PV_ESWITCHES, &(yylsp[(1) - (4)]), &(yylsp[(2) - (4)])); (yyval.pval)->u1.list = (yyvsp[(3) - (4)].pval); set_dads((yyval.pval),(yyvsp[(3) - (4)].pval));;} break; case 132: -#line 619 "ael.y" +#line 664 "ael.y" { (yyval.pval) = NULL; ;} break; case 133: -#line 620 "ael.y" +#line 665 "ael.y" { (yyval.pval) = linku1(nword((yyvsp[(1) - (3)].str), &(yylsp[(1) - (3)])), (yyvsp[(3) - (3)].pval)); ;} break; case 134: -#line 621 "ael.y" - { char *x; asprintf(&x,"%s@%s", (yyvsp[(1) - (5)].str),(yyvsp[(3) - (5)].str)); free((yyvsp[(1) - (5)].str)); free((yyvsp[(3) - (5)].str)); - (yyval.pval) = linku1(nword(x, &(yylsp[(1) - (5)])), (yyvsp[(5) - (5)].pval));;} +#line 666 "ael.y" + { + char *x; + if (asprintf(&x,"%s@%s", (yyvsp[(1) - (5)].str), (yyvsp[(3) - (5)].str)) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + (yyval.pval) = NULL; + } else { + free((yyvsp[(1) - (5)].str)); + free((yyvsp[(3) - (5)].str)); + (yyval.pval) = linku1(nword(x, &(yylsp[(1) - (5)])), (yyvsp[(5) - (5)].pval)); + } + ;} break; case 135: -#line 623 "ael.y" +#line 677 "ael.y" {(yyval.pval)=(yyvsp[(2) - (2)].pval);;} break; case 136: -#line 626 "ael.y" +#line 680 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (1)].str), &(yylsp[(1) - (1)])); ;} break; case 137: -#line 627 "ael.y" +#line 681 "ael.y" { (yyval.pval) = nword((yyvsp[(1) - (3)].str), &(yylsp[(1) - (3)])); (yyval.pval)->u2.arglist = (yyvsp[(3) - (3)].pval); @@ -2996,36 +3050,36 @@ yyreduce: break; case 138: -#line 634 "ael.y" +#line 688 "ael.y" { (yyval.pval) = (yyvsp[(1) - (2)].pval); ;} break; case 139: -#line 635 "ael.y" +#line 689 "ael.y" { (yyval.pval) = linku1((yyvsp[(1) - (3)].pval), (yyvsp[(2) - (3)].pval)); ;} break; case 140: -#line 636 "ael.y" +#line 690 "ael.y" {(yyval.pval)=(yyvsp[(1) - (2)].pval);;} break; case 141: -#line 639 "ael.y" +#line 693 "ael.y" { (yyval.pval) = npval2(PV_INCLUDES, &(yylsp[(1) - (4)]), &(yylsp[(4) - (4)])); (yyval.pval)->u1.list = (yyvsp[(3) - (4)].pval);set_dads((yyval.pval),(yyvsp[(3) - (4)].pval));;} break; case 142: -#line 642 "ael.y" +#line 696 "ael.y" { (yyval.pval) = npval2(PV_INCLUDES, &(yylsp[(1) - (3)]), &(yylsp[(3) - (3)]));;} break; /* Line 1267 of yacc.c. */ -#line 3029 "ael.tab.c" +#line 3083 "ael.tab.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -3245,7 +3299,7 @@ yyreturn: } -#line 647 "ael.y" +#line 701 "ael.y" static char *token_equivs1[] = diff --git a/res/ael/ael.y b/res/ael/ael.y index bcac790961f01e5c9f3b76511ac182bb551bf531..d16d20dffb97ccc2bf9a20d849cca55ef160739a 100644 --- a/res/ael/ael.y +++ b/res/ael/ael.y @@ -319,10 +319,15 @@ statements : /* empty */ { $$ = NULL; } * detect the '-' but only the ':' as separator */ timerange: word3_list COLON word3_list COLON word3_list { - asprintf(&$$, "%s:%s:%s", $1, $3, $5); - free($1); - free($3); - free($5); } + if (asprintf(&$$, "%s:%s:%s", $1, $3, $5) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($3); + free($5); + } + } | word { $$ = $1; } ; @@ -358,50 +363,90 @@ if_like_head : KW_IF test_expr { word_list : word { $$ = $1;} | word word { - asprintf(&($$), "%s%s", $1, $2); - free($1); - free($2); - prev_word = $$;} + if (asprintf(&($$), "%s%s", $1, $2) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($2); + prev_word = $$; + } + } ; hint_word : word { $$ = $1; } | hint_word word { - asprintf(&($$), "%s %s", $1, $2); - free($1); - free($2); } + if (asprintf(&($$), "%s %s", $1, $2) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($2); + } + } | hint_word COLON word { - asprintf(&($$), "%s:%s", $1, $3); - free($1); - free($3); } + if (asprintf(&($$), "%s:%s", $1, $3) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($3); + } + } | hint_word AMPER word { /* there are often '&' in hints */ - asprintf(&($$), "%s&%s", $1, $3); - free($1); - free($3);} - + if (asprintf(&($$), "%s&%s", $1, $3) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($3); + } + } + ; word3_list : word { $$ = $1;} | word word { - asprintf(&($$), "%s%s", $1, $2); - free($1); - free($2); - prev_word = $$;} + if (asprintf(&($$), "%s%s", $1, $2) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($2); + prev_word = $$; + } + } | word word word { - asprintf(&($$), "%s%s%s", $1, $2, $3); - free($1); - free($2); - free($3); - prev_word=$$;} + if (asprintf(&($$), "%s%s%s", $1, $2, $3) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($2); + free($3); + prev_word=$$; + } + } ; goto_word : word { $$ = $1;} | word word { - asprintf(&($$), "%s%s", $1, $2); - free($1); - free($2);} + if (asprintf(&($$), "%s%s", $1, $2) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($2); + } + } | goto_word COLON word { - asprintf(&($$), "%s:%s", $1, $3); - free($1); - free($3);} + if (asprintf(&($$), "%s:%s", $1, $3) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($3); + } + } ; switch_statement : KW_SWITCH test_expr LC case_statements RC { @@ -618,8 +663,17 @@ eswitches : KW_ESWITCHES LC switchlist RC { switchlist : /* empty */ { $$ = NULL; } | word SEMI switchlist { $$ = linku1(nword($1, &@1), $3); } - | word AT word SEMI switchlist { char *x; asprintf(&x,"%s@%s", $1,$3); free($1); free($3); - $$ = linku1(nword(x, &@1), $5);} + | word AT word SEMI switchlist { + char *x; + if (asprintf(&x,"%s@%s", $1, $3) < 0) { + ast_log(LOG_WARNING, "asprintf() failed\n"); + $$ = NULL; + } else { + free($1); + free($3); + $$ = linku1(nword(x, &@1), $5); + } + } | error switchlist {$$=$2;} ; diff --git a/res/ael/ael_lex.c b/res/ael/ael_lex.c index 2a14400010a6d6146a518a20c535c2887b8f916c..62bfc465987ff277e1a740e3666a05f01dfffa85 100644 --- a/res/ael/ael_lex.c +++ b/res/ael/ael_lex.c @@ -9,7 +9,7 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 33 +#define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -32,7 +32,7 @@ /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ -#if __STDC_VERSION__ >= 199901L +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, * if you want the limit (max/min) macros for int types. @@ -55,7 +55,6 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -86,6 +85,8 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif +#endif /* ! C99 */ + #endif /* ! FLEXINT_H */ #ifdef __cplusplus @@ -95,11 +96,12 @@ typedef unsigned int flex_uint32_t; #else /* ! __cplusplus */ -#if __STDC__ +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) #define YY_USE_CONST -#endif /* __STDC__ */ +#endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ #ifdef YY_USE_CONST @@ -135,8 +137,6 @@ typedef void* yyscan_t; #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) #define yy_flex_debug yyg->yy_flex_debug_r -int ael_yylex_init (yyscan_t* scanner); - /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. @@ -194,14 +194,9 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ - #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T -typedef unsigned int yy_size_t; +typedef size_t yy_size_t; #endif #ifndef YY_STRUCT_YY_BUFFER_STATE @@ -950,7 +945,7 @@ static void pbcwhere(const char *text, int *line, int *col ) #define STORE_POS #define STORE_LOC #endif -#line 953 "ael_lex.c" +#line 948 "ael_lex.c" #define INITIAL 0 #define paren 1 @@ -1019,6 +1014,10 @@ static int yy_init_globals (yyscan_t yyscanner ); # define yylloc yyg->yylloc_r +int ael_yylex_init (yyscan_t* scanner); + +int ael_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); + /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ @@ -1098,7 +1097,7 @@ static int input (yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -1163,9 +1162,11 @@ static int input (yyscan_t yyscanner ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int ael_yylex (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner); +extern int ael_yylex \ + (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner); -#define YY_DECL int ael_yylex (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner) +#define YY_DECL int ael_yylex \ + (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -1195,7 +1196,7 @@ YY_DECL #line 208 "ael.flex" -#line 1198 "ael_lex.c" +#line 1199 "ael_lex.c" yylval = yylval_param; @@ -2000,7 +2001,7 @@ YY_RULE_SETUP #line 622 "ael.flex" ECHO; YY_BREAK -#line 2003 "ael_lex.c" +#line 2004 "ael_lex.c" case YY_END_OF_BUFFER: { @@ -2231,7 +2232,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); + yyg->yy_n_chars, (size_t) num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } @@ -2255,6 +2256,14 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else ret_val = EOB_ACT_CONTINUE_SCAN; + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) ael_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + yyg->yy_n_chars += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; @@ -2683,7 +2692,9 @@ static void ael_yyensure_buffer_stack (yyscan_t yyscanner) yyg->yy_buffer_stack = (struct yy_buffer_state**)ael_yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); - + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in ael_yyensure_buffer_stack()" ); + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); yyg->yy_buffer_stack_max = num_to_alloc; @@ -2701,6 +2712,8 @@ static void ael_yyensure_buffer_stack (yyscan_t yyscanner) (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in ael_yyensure_buffer_stack()" ); /* zero only the new slots.*/ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); @@ -2745,7 +2758,7 @@ YY_BUFFER_STATE ael_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yys /** Setup the input buffer state to scan a string. The next call to ael_yylex() will * scan from a @e copy of @a str. - * @param str a NUL-terminated string to scan + * @param yystr a NUL-terminated string to scan * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use @@ -3019,6 +3032,42 @@ int ael_yylex_init(yyscan_t* ptr_yy_globals) return yy_init_globals ( *ptr_yy_globals ); } +/* ael_yylex_init_extra has the same functionality as ael_yylex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to ael_yyalloc in + * the yyextra field. + */ + +int ael_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) + +{ + struct yyguts_t dummy_yyguts; + + ael_yyset_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) ael_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + ael_yyset_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + static int yy_init_globals (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; @@ -3281,7 +3330,9 @@ struct pval *ael2_parse(char *filename, int *errors) my_file = strdup(filename); stat(filename, &stats); buffer = (char*)malloc(stats.st_size+2); - fread(buffer, 1, stats.st_size, fin); + if (fread(buffer, 1, stats.st_size, fin) != stats.st_size) { + ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno)); + } buffer[stats.st_size]=0; fclose(fin); @@ -3349,7 +3400,9 @@ static void setup_filestack(char *fnamebuf2, int fnamebuf_siz, glob_t *globbuf, struct stat stats; stat(fnamebuf2, &stats); buffer = (char*)malloc(stats.st_size+1); - fread(buffer, 1, stats.st_size, in1); + if (fread(buffer, 1, stats.st_size, in1) != stats.st_size) { + ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno)); + } buffer[stats.st_size] = 0; ast_log(LOG_NOTICE," --Read in included file %s, %d chars\n",fnamebuf2, (int)stats.st_size); fclose(in1); diff --git a/res/res_agi.c b/res/res_agi.c index d2a2159502acf34b0588b73c99cb93ff11c8c0fa..eba9ddb9c95f0abd4c9f40486d2298d2bf9c465b 100644 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -2642,7 +2642,8 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi /* If it's voice, write it to the audio pipe */ if ((agi->audio > -1) && (f->frametype == AST_FRAME_VOICE)) { /* Write, ignoring errors */ - write(agi->audio, f->data.ptr, f->datalen); + if (write(agi->audio, f->data.ptr, f->datalen) < 0) { + } } ast_frfree(f); } diff --git a/res/res_config_sqlite.c b/res/res_config_sqlite.c index c3ef1dd1a543fabf8806b512b4bbf968739ecca2..ff3c416cc2adb00a97d5914176733a13589b43ed 100644 --- a/res/res_config_sqlite.c +++ b/res/res_config_sqlite.c @@ -666,7 +666,10 @@ static struct sqlite_cache_tables *find_table(const char *tablename) } /* Table structure not cached; build the structure now */ - asprintf(&sql, sql_table_structure, tablename); + if (asprintf(&sql, sql_table_structure, tablename) < 0) { + ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); + sql = NULL; + } if (!(tblptr = ast_calloc(1, sizeof(*tblptr) + strlen(tablename) + 1))) { AST_RWLIST_UNLOCK(&sqlite_tables); ast_log(LOG_ERROR, "Memory error. Cannot cache table '%s'\n", tablename); diff --git a/res/res_crypto.c b/res/res_crypto.c index f1a2234fd40367514132c797fef82122368db7a3..e55abe891ce4da325bf7160a0f56d5121973e8ba 100644 --- a/res/res_crypto.c +++ b/res/res_crypto.c @@ -106,7 +106,11 @@ static int pw_cb(char *buf, int size, int rwflag, void *userdata) snprintf(prompt, sizeof(prompt), ">>>> passcode for %s key '%s': ", key->ktype == AST_KEY_PRIVATE ? "PRIVATE" : "PUBLIC", key->name); - write(key->outfd, prompt, strlen(prompt)); + if (write(key->outfd, prompt, strlen(prompt)) < 0) { + ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); + key->infd = -2; + return -1; + } memset(buf, 0, sizeof(buf)); tmp = ast_hide_password(key->infd); memset(buf, 0, size); @@ -177,7 +181,9 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd, while(!feof(f)) { /* Calculate a "whatever" quality md5sum of the key */ char buf[256] = ""; - fgets(buf, sizeof(buf), f); + if (!fgets(buf, sizeof(buf), f)) { + continue; + } if (!feof(f)) MD5Update(&md5, (unsigned char *) buf, strlen(buf)); } diff --git a/res/res_http_post.c b/res/res_http_post.c index 28a78e60ae528d6152ef55a30161f87046aacfba..8450fb7ebb6b10ad1cfa55b8c00db8a52d5b6218 100644 --- a/res/res_http_post.c +++ b/res/res_http_post.c @@ -215,8 +215,11 @@ static int readmimefile(FILE * fin, FILE * fout, char * boundary, int contentlen num_to_read = contentlen; } - if(0 < num_to_read) { - fread(&(buf[char_in_buf]), 1, num_to_read, fin); + if (0 < num_to_read) { + if (fread(&(buf[char_in_buf]), 1, num_to_read, fin) < num_to_read) { + ast_log(LOG_WARNING, "fread() failed: %s\n", strerror(errno)); + num_to_read = 0; + } contentlen -= num_to_read; char_in_buf += num_to_read; } @@ -241,9 +244,13 @@ static int readmimefile(FILE * fin, FILE * fout, char * boundary, int contentlen } } if (filespec) { /* If the file name path was found in the header */ - fwrite(buf, 1, marker, fout); + if (fwrite(buf, 1, marker, fout) != marker) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } x = (int)(path_end+1 - filespec); - fwrite(filespec, 1, x, fout); + if (fwrite(filespec, 1, x, fout) != x) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } x = (int)(path_end+1 - buf); memmove(buf, &(buf[x]), char_in_buf-x); char_in_buf -= x; @@ -254,18 +261,24 @@ static int readmimefile(FILE * fin, FILE * fout, char * boundary, int contentlen if (0 > marker) { if (char_in_buf < (boundary_len)) { /*no possibility to find the boundary, write all you have */ - fwrite(buf, 1, char_in_buf, fout); + if (fwrite(buf, 1, char_in_buf, fout) != char_in_buf) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } char_in_buf = 0; } else { /* write all except for area where the boundary marker could be */ - fwrite(buf, 1, char_in_buf -(boundary_len -1), fout); + if (fwrite(buf, 1, char_in_buf -(boundary_len -1), fout) != char_in_buf - (boundary_len - 1)) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } x = char_in_buf -(boundary_len -1); memmove(buf, &(buf[x]), char_in_buf-x); char_in_buf = (boundary_len -1); } } else { /* write up through the boundary, then look for filename in the rest */ - fwrite(buf, 1, marker + boundary_len, fout); + if (fwrite(buf, 1, marker + boundary_len, fout) != marker + boundary_len) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } x = marker + boundary_len; memmove(buf, &(buf[x]), char_in_buf-x); char_in_buf -= marker + boundary_len; diff --git a/res/res_jabber.c b/res/res_jabber.c index 38b1b5959e0710ee12aa96a5db11c78b68ee43dc..ebb1059f58ee88bba880afd491c90563c1943489 100644 --- a/res/res_jabber.c +++ b/res/res_jabber.c @@ -987,8 +987,7 @@ static int aji_act_hook(void *data, int type, iks *node) sprintf(secret, "%s%s", pak->id, client->password); ast_sha1_hash(shasum, secret); handshake = NULL; - asprintf(&handshake, "<handshake>%s</handshake>", shasum); - if (handshake) { + if (asprintf(&handshake, "<handshake>%s</handshake>", shasum) >= 0) { aji_send_raw(client, handshake); ast_free(handshake); handshake = NULL; @@ -2755,8 +2754,7 @@ static int aji_create_client(char *label, struct ast_variable *var, int debug) } if (!strchr(client->user, '/') && !client->component) { /*client */ resource = NULL; - asprintf(&resource, "%s/asterisk", client->user); - if (resource) { + if (asprintf(&resource, "%s/asterisk", client->user) >= 0) { client->jid = iks_id_new(client->stack, resource); ast_free(resource); } @@ -2772,8 +2770,7 @@ static int aji_create_client(char *label, struct ast_variable *var, int debug) } if (!strchr(client->user, '/') && !client->component) { /*client */ resource = NULL; - asprintf(&resource, "%s/asterisk", client->user); - if (resource) { + if (asprintf(&resource, "%s/asterisk", client->user) >= 0) { client->jid = iks_id_new(client->stack, resource); ast_free(resource); } diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 00493467642846d0c0ddfe7540c5aefe198e89e5..fd61cb7a83f32d26e89a7873f0101a7bc771145e 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -513,7 +513,10 @@ static int spawn_mp3(struct mohclass *class) ast_close_fds_above_n(STDERR_FILENO); /* Child */ - chdir(class->dir); + if (chdir(class->dir) < 0) { + ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno)); + _exit(1); + } if (ast_test_flag(class, MOH_CUSTOM)) { execv(argv[0], argv); } else { @@ -917,8 +920,8 @@ static int moh_scan_files(struct mohclass *class) { if (class->dir[0] != '/') { ast_copy_string(dir_path, ast_config_AST_VAR_DIR, sizeof(dir_path)); - strncat(dir_path, "/", sizeof(dir_path)); - strncat(dir_path, class->dir, sizeof(dir_path)); + strncat(dir_path, "/", sizeof(dir_path) - 1); + strncat(dir_path, class->dir, sizeof(dir_path) - 1); } else { ast_copy_string(dir_path, class->dir, sizeof(dir_path)); } @@ -934,8 +937,14 @@ static int moh_scan_files(struct mohclass *class) { class->total_files = 0; dirnamelen = strlen(dir_path) + 2; - getcwd(path, sizeof(path)); - chdir(dir_path); + if (!getcwd(path, sizeof(path))) { + ast_log(LOG_WARNING, "getcwd() failed: %s\n", strerror(errno)); + return -1; + } + if (chdir(path) < 0) { + ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno)); + return -1; + } while ((files_dirent = readdir(files_DIR))) { /* The file name must be at least long enough to have the file type extension */ if ((strlen(files_dirent->d_name) < 4)) @@ -972,7 +981,10 @@ static int moh_scan_files(struct mohclass *class) { } closedir(files_DIR); - chdir(path); + if (chdir(path) < 0) { + ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno)); + return -1; + } if (ast_test_flag(class, MOH_SORTALPHA)) qsort(&class->filearray[0], class->total_files, sizeof(char *), moh_sort_compare); return class->total_files; diff --git a/res/res_phoneprov.c b/res/res_phoneprov.c index 8f5acf13b1690944c0100f72c056ad8fa721b7b2..cd63a265ae9a1359a5b86d5cf87288d7c8e5ec6b 100644 --- a/res/res_phoneprov.c +++ b/res/res_phoneprov.c @@ -451,7 +451,9 @@ static struct ast_str *phoneprov_callback(struct ast_tcptls_session_instance *se ast_get_version(), buf, len, route->file->mime_type); while ((len = read(fd, buf, sizeof(buf))) > 0) { - fwrite(buf, 1, len, ser->f); + if (fwrite(buf, 1, len, ser->f) != len) { + ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + } } close(fd); diff --git a/utils/astcanary.c b/utils/astcanary.c index d4a47c42337b4feb3699308286e90844dea0dfa3..da91e6dd2ea07b2972554907988a19af37888f15 100644 --- a/utils/astcanary.c +++ b/utils/astcanary.c @@ -82,7 +82,9 @@ int main(int argc, char *argv[]) if (utime(argv[1], NULL)) { /* Recreate the file if it doesn't exist */ if ((fd = open(argv[1], O_RDWR | O_TRUNC | O_CREAT, 0777)) > -1) { - write(fd, explanation, strlen(explanation)); + if (write(fd, explanation, strlen(explanation)) < 0) { + exit(1); + } close(fd); } else { exit(1); diff --git a/utils/astman.c b/utils/astman.c index e8d3c4d9ea35ce59ba5b3fc9d80f90d5b68bc158..e116d61657e16e8898b34e7c21119b2e2a7abbc9 100644 --- a/utils/astman.c +++ b/utils/astman.c @@ -151,10 +151,14 @@ static void __attribute__((format (printf, 2, 3))) fdprintf(int fd, char *fmt, . { char stuff[4096]; va_list ap; + int res; + va_start(ap, fmt); vsnprintf(stuff, sizeof(stuff), fmt, ap); va_end(ap); - write(fd, stuff, strlen(stuff)); + if ((res = write(fd, stuff, strlen(stuff))) < 0) { + fprintf(stderr, "write() failed: %s\n", strerror(errno)); + } } static char *get_header(struct message *m, char *var) @@ -418,13 +422,16 @@ static int __attribute__((format (printf, 2, 3))) manager_action(char *action, c struct ast_mansession *s; char tmp[4096]; va_list ap; + int res; s = &session; fdprintf(s->fd, "Action: %s\r\n", action); va_start(ap, fmt); vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); - write(s->fd, tmp, strlen(tmp)); + if ((res = write(s->fd, tmp, strlen(tmp))) < 0) { + fprintf(stderr, "write() failed: %s\n", strerror(errno)); + } fdprintf(s->fd, "\r\n"); return 0; } diff --git a/utils/frame.c b/utils/frame.c index 33a04808f3a301376982801c10dcb039f90d7fef..9f79230b09ec612c27d457fbf2b6adb0f844de3e 100644 --- a/utils/frame.c +++ b/utils/frame.c @@ -59,14 +59,14 @@ int getremainingfilelength( FILE *anyin, long *result) { long i; - i = ftell (anyin); + i = ftell(anyin); if (i == -1) return FALSE; - if (fseek (anyin, 0, SEEK_END) == -1) return FALSE; - *result = ftell (anyin); + if (fseek(anyin, 0, SEEK_END) == -1) return FALSE; + *result = ftell(anyin); if (*result == -1) return FALSE; (*result) -= i; (*result) /= samplewidth; - if (fseek (anyin, i, SEEK_SET) == -1) return FALSE; + if (fseek(anyin, i, SEEK_SET) == -1) return FALSE; return TRUE; } @@ -81,31 +81,39 @@ void readpkheader( FILE *anyin) for (i = 0; i < 11; i++) { - fread( &tempint, 4, 1, anyin); - printf( "%d: %d, ", i, tempint); + if (!fread( &tempint, 4, 1, anyin)) { + return; + } + printf( "%d: %d, ", i, tempint); } printf( "\n"); - fread( blood, 1, 8, anyin); + if (!fread( blood, 1, 8, anyin)) { + return; + } for (i = 0; i < 8; i++) - printf( "%d ", blood[i]); + printf( "%d ", blood[i]); printf( "\n"); for (i = 0; i < 8; i++) - { - for (x = 128; x > 0; x /= 2) - printf((blood[i] & x) == 0? "0 ":"1 "); - printf(i%4==3? "\n":"| "); - } + { + for (x = 128; x > 0; x /= 2) + printf((blood[i] & x) == 0? "0 ":"1 "); + printf(i%4==3? "\n":"| "); + } printf( "\n"); for (i = 0; i < 2; i++) { - fread( &tempint, 4, 1, anyin); - printf( "%d: %d, ", i, tempint); + if (!fread( &tempint, 4, 1, anyin)) { + return; + } + printf( "%d: %d, ", i, tempint); } printf( "\n"); for (i = 0; i < 2; i++) { - fread( &tempushort, 2, 1, anyin); - printf( "%d: %d, ", i, tempushort); + if (!fread( &tempushort, 2, 1, anyin)) { + return; + } + printf( "%d: %d, ", i, tempushort); } printf( "\n"); } @@ -125,59 +133,81 @@ void readwavheader( FILE *anyin) iswav = FALSE; if (ftell(anyin) == -1) /* If we cannot seek this file */ - { - nowav = TRUE; /* -> Pretend this is no wav-file */ - chat("File not seekable: not checking for WAV-header.\n"); - } + { + nowav = TRUE; /* -> Pretend this is no wav-file */ + chat("File not seekable: not checking for WAV-header.\n"); + } else - { - /* Expect four bytes "RIFF" and four bytes filelength */ - fread (str, 1, 8, anyin); /* 0 */ - str[4] = '\0'; - if (strcmp(str, "RIFF") != 0) nowav = TRUE; - /* Expect eight bytes "WAVEfmt " */ - fread (str, 1, 8, anyin); /* 8 */ - str[8] = '\0'; - if (strcmp(str, "WAVEfmt ") != 0) nowav = TRUE; - /* Expect length of fmt data, which should be 16 */ - fread (&tempuint, 4, 1, anyin); /* 16 */ - if (tempuint != 16) nowav = TRUE; - /* Expect format tag, which should be 1 for pcm */ - fread (&tempushort, 2, 1, anyin); /* 20 */ - if (tempushort != 1) - nowav = TRUE; - /* Expect number of channels */ - fread (&cn, 2, 1, anyin); /* 20 */ - if (cn != 1 && cn != 2) nowav = TRUE; - /* Read samplefrequency */ - fread (&sf, 4, 1, anyin); /* 24 */ - /* Read bytes per second: Should be samplefreq * channels * 2 */ - fread (&tempuint, 4, 1, anyin); /* 28 */ - if (tempuint != sf * cn * 2) nowav = TRUE; - /* read bytes per frame: Should be channels * 2 */ - fread (&tempushort, 2, 1, anyin); /* 32 */ - if (tempushort != cn * 2) nowav = TRUE; - /* Read bits per sample: Should be 16 */ - fread (&tempushort, 2, 1, anyin); /* 34 */ - if (tempushort != 16) nowav = TRUE; - fread (str, 4, 1, anyin); /* 36 */ - str[4] = '\0'; - if (strcmp(str, "data") != 0) nowav = TRUE; - fread (&tempuint, 4, 1, anyin); /* 40 */ - if (nowav) - { - fseek (anyin, 0, SEEK_SET); /* Back to beginning of file */ - chat("File has no WAV header.\n"); - } - else - { - samplefrequency = sf; - channels = cn; - chat ("Read WAV header: %d channels, samplefrequency %d.\n", - channels, samplefrequency); - iswav = TRUE; - } - } + { + /* Expect four bytes "RIFF" and four bytes filelength */ + if (!fread(str, 1, 8, anyin)) { /* 0 */ + return; + } + str[4] = '\0'; + if (strcmp(str, "RIFF") != 0) nowav = TRUE; + /* Expect eight bytes "WAVEfmt " */ + if (!fread(str, 1, 8, anyin)) { /* 8 */ + return; + } + str[8] = '\0'; + if (strcmp(str, "WAVEfmt ") != 0) nowav = TRUE; + /* Expect length of fmt data, which should be 16 */ + if (!fread(&tempuint, 4, 1, anyin)) { /* 16 */ + return; + } + if (tempuint != 16) nowav = TRUE; + /* Expect format tag, which should be 1 for pcm */ + if (!fread(&tempushort, 2, 1, anyin)) { /* 20 */ + return; + } + if (tempushort != 1) + nowav = TRUE; + /* Expect number of channels */ + if (!fread(&cn, 2, 1, anyin)) { /* 20 */ + return; + } + if (cn != 1 && cn != 2) nowav = TRUE; + /* Read samplefrequency */ + if (!fread(&sf, 4, 1, anyin)) { /* 24 */ + return; + } + /* Read bytes per second: Should be samplefreq * channels * 2 */ + if (!fread(&tempuint, 4, 1, anyin)) { /* 28 */ + return; + } + if (tempuint != sf * cn * 2) nowav = TRUE; + /* read bytes per frame: Should be channels * 2 */ + if (!fread(&tempushort, 2, 1, anyin)) { /* 32 */ + return; + } + if (tempushort != cn * 2) nowav = TRUE; + /* Read bits per sample: Should be 16 */ + if (!fread(&tempushort, 2, 1, anyin)) { /* 34 */ + return; + } + if (tempushort != 16) nowav = TRUE; + if (!fread(str, 4, 1, anyin)) { /* 36 */ + return; + } + str[4] = '\0'; + if (strcmp(str, "data") != 0) nowav = TRUE; + if (!fread(&tempuint, 4, 1, anyin)) { /* 40 */ + return; + } + if (nowav) + { + fseek(anyin, 0, SEEK_SET); /* Back to beginning of file */ + chat("File has no WAV header.\n"); + } + else + { + samplefrequency = sf; + channels = cn; + chat("Read WAV header: %d channels, samplefrequency %d.\n", + channels, samplefrequency); + iswav = TRUE; + } + } return; } @@ -192,36 +222,62 @@ void makewavheader( void) unsigned short tempushort; /* If fseek fails, don't create the header. */ - if (fseek (out, 0, SEEK_END) != -1) - { - filelength = ftell (out); - chat ("filelength %d, ", filelength); - fseek (out, 0, SEEK_SET); - fwrite ("RIFF", 1, 4, out); /* 0 */ - tempuint = filelength - 8; fwrite (&tempuint, 4, 1, out); /* 4 */ - fwrite ("WAVEfmt ", 1, 8, out); /* 8 */ - /* length of fmt data 16 bytes */ - tempuint = 16; - fwrite (&tempuint, 4, 1, out); /* 16 */ - /* Format tag: 1 for pcm */ - tempushort = 1; - fwrite (&tempushort, 2, 1, out); /* 20 */ - chat ("%d channels\n", channels); - fwrite (&channels, 2, 1, out); - chat ("samplefrequency %d\n", samplefrequency); - fwrite (&samplefrequency, 4, 1, out); /* 24 */ - /* Bytes per second */ - tempuint = channels * samplefrequency * 2; - fwrite (&tempuint, 4, 1, out); /* 28 */ - /* Block align */ - tempushort = 2 * channels; - fwrite (&tempushort, 2, 1, out); /* 32 */ - /* Bits per sample */ - tempushort = 16; - fwrite (&tempushort, 2, 1, out); /* 34 */ - fwrite ("data", 4, 1, out); /* 36 */ - tempuint = filelength - 44; fwrite (&tempuint, 4, 1, out); /* 40 */ - } + if (fseek(out, 0, SEEK_END) != -1) + { + filelength = ftell(out); + chat("filelength %d, ", filelength); + fseek(out, 0, SEEK_SET); + if (!fwrite("RIFF", 1, 4, out)) { /* 0 */ + return; + } + tempuint = filelength - 8; + if (!fwrite(&tempuint, 4, 1, out)) { /* 4 */ + return; + } + if (!fwrite("WAVEfmt ", 1, 8, out)) { /* 8 */ + return; + } + /* length of fmt data 16 bytes */ + tempuint = 16; + if (!fwrite(&tempuint, 4, 1, out)) { /* 16 */ + return; + } + /* Format tag: 1 for pcm */ + tempushort = 1; + if (!fwrite(&tempushort, 2, 1, out)) { /* 20 */ + return; + } + chat("%d channels\n", channels); + if (!fwrite(&channels, 2, 1, out)) { + return; + } + chat("samplefrequency %d\n", samplefrequency); + if (!fwrite(&samplefrequency, 4, 1, out)) { /* 24 */ + return; + } + /* Bytes per second */ + tempuint = channels * samplefrequency * 2; + if (!fwrite(&tempuint, 4, 1, out)) { /* 28 */ + return; + } + /* Block align */ + tempushort = 2 * channels; + if (!fwrite(&tempushort, 2, 1, out)) { /* 32 */ + return; + } + /* Bits per sample */ + tempushort = 16; + if (!fwrite(&tempushort, 2, 1, out)) { /* 34 */ + return; + } + if (!fwrite("data", 4, 1, out)) { /* 36 */ + return; + } + tempuint = filelength - 44; + if (!fwrite(&tempuint, 4, 1, out)) { /* 40 */ + return; + } + } return; } @@ -870,10 +926,10 @@ int myexit (int value) case 0: if (wavout) makewavheader(); /* Writes a fully informed .WAV header */ - chat ("Success!\n"); + chat("Success!\n"); break; default: - chat ("Failure.\n"); + chat("Failure.\n"); break; } exit (value); @@ -903,7 +959,9 @@ int workloop( FILE *theinfile, FILE *theoutfile, /* Call the routine that does the work */ if (!work (buffer, nowlength)) /* On error, stop. */ return FALSE; - fwrite(buffer, sizeof(short), nowlength, theoutfile); + if (!fwrite(buffer, sizeof(short), nowlength, theoutfile)) { + return FALSE; + } if (ferror( theoutfile) != 0) fatalperror("Error writing to output file"); } diff --git a/utils/muted.c b/utils/muted.c index 864e0cf5b8e1bd79897520502efd733f3893bdc2..b2523b6fce6a983c04424de743dfbdd3ba67a157 100644 --- a/utils/muted.c +++ b/utils/muted.c @@ -116,7 +116,9 @@ static int load_config(void) return -1; } while(!feof(f)) { - fgets(buf, sizeof(buf), f); + if (!fgets(buf, sizeof(buf), f)) { + continue; + } if (!feof(f)) { lineno++; val = strchr(buf, '#'); @@ -684,7 +686,10 @@ int main(int argc, char *argv[]) } if (needfork) { #ifndef HAVE_SBIN_LAUNCHD - daemon(0,0); + if (daemon(0,0) < 0) { + fprintf(stderr, "daemon() failed: %s\n", strerror(errno)); + exit(1); + } #else fprintf(stderr, "Mac OS X detected. Use 'launchd -d muted -f' to launch.\n"); exit(1); diff --git a/utils/stereorize.c b/utils/stereorize.c index 7d72cbdbfa1e3b3a9e8ac6fe6b184c93a6f2a484..c8428320d673b122ffd727e2f69453117a9f9526 100644 --- a/utils/stereorize.c +++ b/utils/stereorize.c @@ -150,10 +150,10 @@ int main( int argcount, char *args[]) for (; i < maxk; i++) stereosample[2 * i + 1] = 0; - fwrite(stereosample, sizeof(*leftsample), 2 * maxk, out); - if (ferror( out) != 0) - fatalerror("Error writing to file '%s': %s\n", - outfilename, strerror(errno)); + if (!fwrite(stereosample, sizeof(*leftsample), 2 * maxk, out)) { + fatalerror("Error writing to file '%s': %s\n", + outfilename, strerror(errno)); + } } /* That was an endless loop. This point is never reached. */ } diff --git a/utils/streamplayer.c b/utils/streamplayer.c index fb0d055a24efb45150551e95f31e5e084c4315a2..ebb12e54bdd6bc64ee199e82171861264f54e944 100644 --- a/utils/streamplayer.c +++ b/utils/streamplayer.c @@ -112,8 +112,11 @@ int main(int argc, char *argv[]) select(2, NULL, &wfds, NULL, &tv); - if (FD_ISSET(1, &wfds)) - write(1, buf, res); + if (FD_ISSET(1, &wfds)) { + if (write(1, buf, res) < 1) { + break; + } + } } close(s);