WTAP_ERR_UNWRITABLE_ errors aren't returned by reads or open-for-reading.

Check for them *only* on opening for writing and writes.

Change-Id: I4b537d511ec04bcfc81f69166a2b9a2ee9310067
Reviewed-on: https://code.wireshark.org/review/5827
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2014-12-17 16:41:21 -08:00
parent aa27e665b1
commit 6011a047d3
10 changed files with 9 additions and 88 deletions

View File

@ -905,10 +905,8 @@ process_cap_file(wtap *wth, const char *filename)
break;
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_DECOMPRESS:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
/* fallthrough */
@ -1486,10 +1484,8 @@ main(int argc, char *argv[])
switch (err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_DECOMPRESS:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;

View File

@ -144,15 +144,8 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
break;
case WTAP_ERR_UNWRITABLE_ENCAP:
if (for_writing)
errmsg = "Wireshark can't save this capture in that format.";
else {
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"The file \"%%s\" is a capture for a network type that Wireshark doesn't support.\n"
"(%s)", err_info);
g_free(err_info);
errmsg = errmsg_errno;
}
/* Seen only when opening a capture file for writing. */
errmsg = "Wireshark can't save this capture in that format.";
break;
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:

View File

@ -257,9 +257,7 @@ main(int argc, char *argv[])
switch (err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;

View File

@ -1251,9 +1251,7 @@ main(int argc, char *argv[])
wtap_strerror(err));
switch (err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;
@ -1718,9 +1716,7 @@ main(int argc, char *argv[])
argv[optind], wtap_strerror(err));
switch (err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;

38
file.c
View File

@ -747,13 +747,6 @@ cf_read(capture_file *cf, gboolean reloading)
g_free(err_info);
break;
case WTAP_ERR_UNWRITABLE_ENCAP:
simple_error_message_box(
"The capture file has a packet with a network type that Wireshark doesn't support.\n(%s)",
err_info);
g_free(err_info);
break;
case WTAP_ERR_SHORT_READ:
simple_error_message_box(
"The capture file appears to have been cut short"
@ -1526,13 +1519,6 @@ cf_merge_files(char **out_filenamep, int in_file_count,
display_basename = g_filename_display_basename(in_files[i].filename);
switch (read_err) {
case WTAP_ERR_UNWRITABLE_ENCAP:
simple_error_message_box(
"The capture file %s has a packet with a network type that Wireshark doesn't support.\n(%s)",
display_basename, err_info);
g_free(err_info);
break;
case WTAP_ERR_SHORT_READ:
simple_error_message_box(
"The capture file %s appears to have been cut short"
@ -1758,12 +1744,6 @@ cf_read_record_r(capture_file *cf, const frame_data *fdata,
display_basename = g_filename_display_basename(cf->filename);
switch (err) {
case WTAP_ERR_UNWRITABLE_ENCAP:
simple_error_message_box("The file \"%s\" has a packet with a network type that Wireshark doesn't support.\n(%s)",
display_basename, err_info);
g_free(err_info);
break;
case WTAP_ERR_BAD_FILE:
simple_error_message_box("An error occurred while reading from the file \"%s\": %s.\n(%s)",
display_basename, wtap_strerror(err), err_info);
@ -4543,13 +4523,6 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
g_free(err_info);
break;
case WTAP_ERR_UNWRITABLE_ENCAP:
simple_error_message_box(
"The capture file has a packet with a network type that Wireshark doesn't support.\n(%s)",
err_info);
g_free(err_info);
break;
case WTAP_ERR_SHORT_READ:
simple_error_message_box(
"The capture file appears to have been cut short"
@ -5082,15 +5055,8 @@ cf_open_failure_alert_box(const char *filename, int err, gchar *err_info,
break;
case WTAP_ERR_UNWRITABLE_ENCAP:
if (for_writing) {
simple_error_message_box("Wireshark can't save this capture in that format.");
} else {
simple_error_message_box(
"The file \"%s\" is a capture for a network type that Wireshark doesn't support.\n"
"(%s)",
display_basename, err_info);
g_free(err_info);
}
/* Seen only when opening a capture file for writing. */
simple_error_message_box("Wireshark can't save this capture in that format.");
break;
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:

View File

@ -58,8 +58,8 @@ frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf)
* frame_tvb->tvb.length + frame_tvb->offset?
*/
if (!wtap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, &err, &err_info)) {
/* XXX - report error! */
switch (err) {
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
g_free(err_info);
break;

View File

@ -377,9 +377,7 @@ main(int argc, char *argv[])
switch (open_err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;
@ -547,9 +545,7 @@ main(int argc, char *argv[])
switch (read_err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;

View File

@ -1012,12 +1012,6 @@ load_cap_file(capture_file *cf)
g_free(err_info);
break;
case WTAP_ERR_UNWRITABLE_ENCAP:
cmdarg_err("The file \"%s\" has a packet with a network type that Rawshark doesn't support.\n(%s)",
cf->filename, err_info);
g_free(err_info);
break;
case WTAP_ERR_SHORT_READ:
cmdarg_err("The file \"%s\" appears to have been cut short in the middle of a packet.",
cf->filename);

View File

@ -124,9 +124,7 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
switch (err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;
@ -298,9 +296,7 @@ main(int argc, char *argv[])
switch (err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;
@ -356,9 +352,7 @@ main(int argc, char *argv[])
switch (err) {
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNWRITABLE_ENCAP:
case WTAP_ERR_BAD_FILE:
case WTAP_ERR_UNWRITABLE_REC_DATA:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;

View File

@ -3469,12 +3469,6 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
g_free(err_info);
break;
case WTAP_ERR_UNWRITABLE_ENCAP:
cmdarg_err("The file \"%s\" has a packet with a network type that TShark doesn't support.\n(%s)",
cf->filename, err_info);
g_free(err_info);
break;
case WTAP_ERR_SHORT_READ:
cmdarg_err("The file \"%s\" appears to have been cut short in the middle of a packet.",
cf->filename);
@ -4224,16 +4218,10 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
break;
case WTAP_ERR_UNWRITABLE_ENCAP:
if (for_writing) {
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"TShark can't save this capture as a \"%s\" file.",
wtap_file_type_subtype_short_string(file_type));
} else {
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"The file \"%%s\" is a capture for a network type that TShark doesn't support.\n"
"(%s)", err_info);
g_free(err_info);
}
/* Seen only when opening a capture file for writing. */
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"TShark can't save this capture as a \"%s\" file.",
wtap_file_type_subtype_short_string(file_type));
errmsg = errmsg_errno;
break;