aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2007-05-02 19:28:24 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2007-05-02 19:28:24 +0000
commit6ef6da0c112b677a3e86a1cca38a2c42f0109944 (patch)
tree80c7d1c43538fefe03c09623ca2e54fc5cde04b1 /gtk
parentb14ee29999fd3d4daa1c3c7ec45d69a8632bd936 (diff)
Immediately quit routines if fwrite() fails - further writes will
probably fail (as you're probably out of disk space or over quota), and, even if they don't, the file's going to be corrupt in any case. (Hopefully that's sufficient to avoid warnings that we're ignoring the result of fwrite().) For fread(), check for errors or short reads, at least in all cases where we have a provision for failing if the read fails. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@21649 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'gtk')
-rw-r--r--gtk/follow_dlg.c57
-rw-r--r--gtk/rtp_stream.c29
2 files changed, 62 insertions, 24 deletions
diff --git a/gtk/follow_dlg.c b/gtk/follow_dlg.c
index 7cf85d9685..59e012caae 100644
--- a/gtk/follow_dlg.c
+++ b/gtk/follow_dlg.c
@@ -266,6 +266,37 @@ follow_stream_cb(GtkWidget * w, gpointer data _U_)
/* Free the filter string, as we're done with it. */
g_free(follow_filter);
+ /* Go back to the top of the file and read the first tcp_stream_chunk
+ * to ensure that the IP addresses and port numbers in the drop-down
+ * list are tied to the correct lines displayed by follow_read_stream()
+ * later on (which also reads from this file). Close the file when
+ * we're done.
+ *
+ * We read the data now, before we pop up a window, in case the
+ * read fails. We use the data later.
+ */
+
+ rewind(data_out_file);
+ nchars=fread(&sc, 1, sizeof(sc), data_out_file);
+ if (nchars != sizeof(sc)) {
+ if (ferror(data_out_file)) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Could not read from temporary file %s: %s",
+ follow_info->data_out_filename, strerror(errno));
+ } else {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Short read from temporary file %s: expected %lu, got %lu",
+ follow_info->data_out_filename,
+ (unsigned long)sizeof(sc),
+ (unsigned long)nchars);
+ }
+ eth_close(tmp_fd);
+ unlink(follow_info->data_out_filename);
+ g_free(follow_info);
+ return;
+ }
+ fclose(data_out_file);
+
/* The data_out_filename file now has all the text that was in the session */
streamwindow = dlg_window_new("Follow TCP Stream");
@@ -376,17 +407,6 @@ follow_stream_cb(GtkWidget * w, gpointer data _U_)
gtk_widget_show(stream_mi);
follow_info->show_stream = BOTH_HOSTS;
- /* Go back to the top of the file and read the first tcp_stream_chunk
- * to ensure that the IP addresses and port numbers in the drop-down
- * list are tied to the correct lines displayed by follow_read_stream()
- * later on (which also reads from this file). Close the file when
- * we're done.
- */
-
- rewind(data_out_file);
- nchars=fread(&sc, 1, sizeof(sc), data_out_file);
- fclose(data_out_file);
-
/* Host 0 --> Host 1 */
if(sc.src_port == strtol(port0, NULL, 10)) {
g_snprintf(string, sizeof(string), "%s:%s --> %s:%s (%u bytes)",
@@ -662,6 +682,16 @@ follow_read_stream(follow_info_t *follow_info,
}
while ((nchars=fread(&sc, 1, sizeof(sc), data_out_file))) {
+ if (nchars != sizeof(sc)) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Short read from temporary file %s: expected %lu, got %lu",
+ follow_info->data_out_filename,
+ (unsigned long)sizeof(sc),
+ (unsigned long)nchars);
+ fclose(data_out_file);
+ data_out_file = NULL;
+ return FRS_READ_ERROR;
+ }
if (client_port == 0) {
memcpy(client_addr, sc.src_addr, iplen);
client_port = sc.src_port;
@@ -688,6 +718,7 @@ follow_read_stream(follow_info_t *follow_info,
nchars = fread(buffer, 1, bcount, data_out_file);
if (nchars == 0)
break;
+ /* XXX - if we don't get "bcount" bytes, is that an error? */
sc.dlen -= nchars;
if (!skip) {
@@ -818,8 +849,8 @@ follow_read_stream(follow_info_t *follow_info,
return FRS_READ_ERROR;
}
- fclose(data_out_file);
- data_out_file = NULL;
+ fclose(data_out_file);
+ data_out_file = NULL;
return FRS_OK;
print_error:
diff --git a/gtk/rtp_stream.c b/gtk/rtp_stream.c
index d41378e332..11c1de7c65 100644
--- a/gtk/rtp_stream.c
+++ b/gtk/rtp_stream.c
@@ -156,7 +156,6 @@ static void rtp_write_header(rtp_stream_info_t *strinfo, FILE *file)
size_t sourcelen;
guint16 port; /* UDP port */
guint16 padding; /* 2 padding bytes */
- size_t nchars;
fprintf(file, "#!rtpplay%s %s/%u\n", RTPFILE_VERSION,
get_addr_name(&(strinfo->dest_addr)),
@@ -173,11 +172,16 @@ static void rtp_write_header(rtp_stream_info_t *strinfo, FILE *file)
port = g_htons(strinfo->src_port);
padding = 0;
- nchars=fwrite(&start_sec, 4, 1, file);
- nchars=fwrite(&start_usec, 4, 1, file);
- nchars=fwrite(&source, 4, 1, file);
- nchars=fwrite(&port, 2, 1, file);
- nchars=fwrite(&padding, 2, 1, file);
+ if (fwrite(&start_sec, 4, 1, file) == 0)
+ return;
+ if (fwrite(&start_usec, 4, 1, file) == 0)
+ return;
+ if (fwrite(&source, 4, 1, file) == 0)
+ return;
+ if (fwrite(&port, 2, 1, file) == 0)
+ return;
+ if (fwrite(&padding, 2, 1, file) == 0)
+ return;
}
/* utility function for writing a sample to file in rtpdump -F dump format (.rtp)*/
@@ -187,16 +191,19 @@ static void rtp_write_sample(rtp_sample_t* sample, FILE* file)
be smaller than plen if not whole packet recorded) */
guint16 plen; /* actual header+payload length for RTP, 0 for RTCP */
guint32 offset; /* milliseconds since the start of recording */
- size_t nchars;
length = g_htons(sample->header.frame_length + 8);
plen = g_htons(sample->header.frame_length);
offset = g_htonl(sample->header.rec_time);
- nchars=fwrite(&length, 2, 1, file);
- nchars=fwrite(&plen, 2, 1, file);
- nchars=fwrite(&offset, 4, 1, file);
- nchars=fwrite(sample->frame, sample->header.frame_length, 1, file);
+ if (fwrite(&length, 2, 1, file) == 0)
+ return;
+ if (fwrite(&plen, 2, 1, file) == 0)
+ return;
+ if (fwrite(&offset, 4, 1, file) == 0)
+ return;
+ if (fwrite(sample->frame, sample->header.frame_length, 1, file) == 0)
+ return;
}