Bug 1852662 - Fix UndefinedBehaviorSanitizer warning in mimebuf.cpp:132. r=BenC
Differential Revision: https://phabricator.services.mozilla.com/D222284 --HG-- extra : rebase_source : 4604bd88c3f31aa0b5443291acd65e55456fdc7e extra : amend_source : 85b19c81ad1fd1c475e44c77c3df6d5e41e94186
This commit is contained in:
Родитель
726325f7ee
Коммит
506b01de88
|
@ -19,6 +19,7 @@
|
|||
#include "prlog.h"
|
||||
#include "msgCore.h"
|
||||
#include "nsMimeStringResources.h"
|
||||
#include "mimeobj.h"
|
||||
|
||||
extern "C" int mime_GrowBuffer(uint32_t desired_size, uint32_t element_size,
|
||||
uint32_t quantum, char** buffer, int32_t* size) {
|
||||
|
@ -81,10 +82,12 @@ extern "C" int mime_ReBuffer(const char* net_buffer, int32_t net_buffer_size,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int convert_and_send_buffer(
|
||||
char* buf, int length, bool convert_newlines_p,
|
||||
int32_t (*per_line_fn)(char* line, uint32_t line_length, void* closure),
|
||||
void* closure) {
|
||||
static int convert_and_send_buffer(char* buf, int length,
|
||||
bool convert_newlines_p,
|
||||
int32_t (*per_line_fn)(const char* line,
|
||||
int32_t line_length,
|
||||
MimeObject* closure),
|
||||
MimeObject* closure) {
|
||||
/* Convert the line terminator to the native form.
|
||||
*/
|
||||
char* newline;
|
||||
|
@ -132,11 +135,13 @@ static int convert_and_send_buffer(
|
|||
return (*per_line_fn)(buf, length, closure);
|
||||
}
|
||||
|
||||
extern "C" int mime_LineBuffer(
|
||||
const char* net_buffer, int32_t net_buffer_size, char** bufferP,
|
||||
int32_t* buffer_sizeP, uint32_t* buffer_fpP, bool convert_newlines_p,
|
||||
int32_t (*per_line_fn)(char* line, uint32_t line_length, void* closure),
|
||||
void* closure) {
|
||||
extern "C" int mime_LineBuffer(const char* net_buffer, int32_t net_buffer_size,
|
||||
char** bufferP, int32_t* buffer_sizeP,
|
||||
uint32_t* buffer_fpP, bool convert_newlines_p,
|
||||
int32_t (*per_line_fn)(const char* line,
|
||||
int32_t line_length,
|
||||
MimeObject* closure),
|
||||
MimeObject* closure) {
|
||||
int status = 0;
|
||||
if (*buffer_fpP > 0 && *bufferP && (*buffer_fpP < (uint32_t)*buffer_sizeP) &&
|
||||
(*bufferP)[*buffer_fpP - 1] == '\r' && net_buffer_size > 0 &&
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
extern "C" int mime_GrowBuffer(uint32_t desired_size, uint32_t element_size,
|
||||
uint32_t quantum, char** buffer, int32_t* size);
|
||||
|
||||
extern "C" int mime_LineBuffer(
|
||||
const char* net_buffer, int32_t net_buffer_size, char** bufferP,
|
||||
int32_t* buffer_sizeP, int32_t* buffer_fpP, bool convert_newlines_p,
|
||||
int32_t (*per_line_fn)(char* line, int32_t line_length, void* closure),
|
||||
void* closure);
|
||||
extern "C" int mime_LineBuffer(const char* net_buffer, int32_t net_buffer_size,
|
||||
char** bufferP, int32_t* buffer_sizeP,
|
||||
int32_t* buffer_fpP, bool convert_newlines_p,
|
||||
int32_t (*per_line_fn)(const char* line,
|
||||
int32_t line_length,
|
||||
MimeObject* closure),
|
||||
MimeObject* closure);
|
||||
|
||||
extern "C" int mime_ReBuffer(const char* net_buffer, int32_t net_buffer_size,
|
||||
uint32_t desired_buffer_size, char** bufferP,
|
||||
|
|
|
@ -39,7 +39,7 @@ static int MimeEncrypted_parse_end(MimeObject*, bool);
|
|||
static int MimeEncrypted_add_child(MimeObject*, MimeObject*);
|
||||
|
||||
static int MimeHandleDecryptedOutput(const char*, int32_t, void*);
|
||||
static int MimeHandleDecryptedOutputLine(char*, int32_t, MimeObject*);
|
||||
static int MimeHandleDecryptedOutputLine(const char*, int32_t, MimeObject*);
|
||||
static int MimeEncrypted_close_headers(MimeObject*);
|
||||
static int MimeEncrypted_emit_buffered_child(MimeObject*);
|
||||
|
||||
|
@ -264,14 +264,11 @@ static int MimeHandleDecryptedOutput(const char* buf, int32_t buf_size,
|
|||
|
||||
/* Is it truly safe to use ibuffer here? I think so... */
|
||||
return mime_LineBuffer(buf, buf_size, &obj->ibuffer, &obj->ibuffer_size,
|
||||
&obj->ibuffer_fp, true,
|
||||
((int (*)(char*, int32_t, void*))
|
||||
/* This cast is to turn void into MimeObject */
|
||||
MimeHandleDecryptedOutputLine),
|
||||
&obj->ibuffer_fp, true, MimeHandleDecryptedOutputLine,
|
||||
obj);
|
||||
}
|
||||
|
||||
static int MimeHandleDecryptedOutputLine(char* line, int32_t length,
|
||||
static int MimeHandleDecryptedOutputLine(const char* line, int32_t length,
|
||||
MimeObject* obj) {
|
||||
/* Largely the same as MimeMessage_parse_line (the other MIME container
|
||||
type which contains exactly one child.)
|
||||
|
|
|
@ -215,11 +215,7 @@ static int MimeObject_parse_buffer(const char* buffer, int32_t size,
|
|||
if (obj->closed_p) return -1;
|
||||
|
||||
return mime_LineBuffer(buffer, size, &obj->ibuffer, &obj->ibuffer_size,
|
||||
&obj->ibuffer_fp, true,
|
||||
((int (*)(char*, int32_t, void*))
|
||||
/* This cast is to turn void into MimeObject */
|
||||
obj->clazz->parse_line),
|
||||
obj);
|
||||
&obj->ibuffer_fp, true, obj->clazz->parse_line, obj);
|
||||
}
|
||||
|
||||
static int MimeObject_parse_line(const char* line, int32_t length,
|
||||
|
|
|
@ -35,9 +35,10 @@ static int MimeInlineText_parse_eof(MimeObject* obj, bool abort_p);
|
|||
static int MimeInlineText_parse_end(MimeObject*, bool);
|
||||
static int MimeInlineText_parse_decoded_buffer(const char*, int32_t,
|
||||
MimeObject*);
|
||||
static int MimeInlineText_rotate_convert_and_parse_line(char*, int32_t,
|
||||
static int MimeInlineText_rotate_convert_and_parse_line(const char*, int32_t,
|
||||
MimeObject*);
|
||||
static int MimeInlineText_open_dam(char* line, int32_t length, MimeObject* obj);
|
||||
static int MimeInlineText_open_dam(const char* line, int32_t length,
|
||||
MimeObject* obj);
|
||||
static int MimeInlineText_initializeCharset(MimeObject* obj);
|
||||
|
||||
static int MimeInlineTextClassInitialize(MimeObjectClass* oclass) {
|
||||
|
@ -267,10 +268,7 @@ static int MimeInlineText_parse_decoded_buffer(const char* buf, int32_t size,
|
|||
// `parse_line` method instead of calling the `parse_line` method directly.
|
||||
return mime_LineBuffer(buf, size, &obj->ibuffer, &obj->ibuffer_size,
|
||||
&obj->ibuffer_fp, true,
|
||||
((int (*)(char*, int32_t, void*))
|
||||
/* This cast is to turn void into MimeObject */
|
||||
MimeInlineText_rotate_convert_and_parse_line),
|
||||
obj);
|
||||
MimeInlineText_rotate_convert_and_parse_line, obj);
|
||||
}
|
||||
|
||||
#define MimeInlineText_grow_cbuffer(text, desired_size) \
|
||||
|
@ -279,7 +277,8 @@ static int MimeInlineText_parse_decoded_buffer(const char* buf, int32_t size,
|
|||
&(text)->cbuffer_size) \
|
||||
: 0)
|
||||
|
||||
static int MimeInlineText_convert_and_parse_line(char* line, int32_t length,
|
||||
static int MimeInlineText_convert_and_parse_line(const char* line,
|
||||
int32_t length,
|
||||
MimeObject* obj) {
|
||||
int status;
|
||||
nsAutoCString converted;
|
||||
|
@ -309,7 +308,7 @@ static int MimeInlineText_convert_and_parse_line(char* line, int32_t length,
|
|||
line, length, text->charset, converted, obj->options->stream_closure);
|
||||
|
||||
if (status == 0) {
|
||||
line = (char*)converted.get();
|
||||
line = converted.get();
|
||||
length = converted.Length();
|
||||
}
|
||||
|
||||
|
@ -323,7 +322,7 @@ static int MimeInlineText_convert_and_parse_line(char* line, int32_t length,
|
|||
// In this function call, all buffered lines in lineDam will be sent to charset
|
||||
// detector and a charset will be used to parse all those line and following
|
||||
// lines in this mime obj.
|
||||
static int MimeInlineText_open_dam(char* line, int32_t length,
|
||||
static int MimeInlineText_open_dam(const char* line, int32_t length,
|
||||
MimeObject* obj) {
|
||||
MimeInlineText* text = (MimeInlineText*)obj;
|
||||
nsAutoCString detectedCharset;
|
||||
|
@ -375,20 +374,35 @@ static int MimeInlineText_open_dam(char* line, int32_t length,
|
|||
return status;
|
||||
}
|
||||
|
||||
static int MimeInlineText_rotate_convert_and_parse_line(char* line,
|
||||
int32_t length,
|
||||
MimeObject* obj) {
|
||||
static int MimeInlineText_rotate_convert_and_parse_line(
|
||||
const char* original_line, int32_t length, MimeObject* obj) {
|
||||
int status = 0;
|
||||
MimeInlineTextClass* textc = (MimeInlineTextClass*)obj->clazz;
|
||||
|
||||
PR_ASSERT(!obj->closed_p);
|
||||
if (obj->closed_p) return -1;
|
||||
|
||||
const char* line = nullptr;
|
||||
char* rotated_line = nullptr;
|
||||
|
||||
// Rotate the line, if desired (this happens on the raw data, before any
|
||||
// charset conversion).
|
||||
if (obj->options && obj->options->rot13_p) {
|
||||
status = textc->rot13_line(obj, line, length);
|
||||
if (status < 0) return status;
|
||||
rotated_line = (char*)PR_Malloc(length);
|
||||
if (!rotated_line) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(rotated_line, line, length);
|
||||
|
||||
status = textc->rot13_line(obj, rotated_line, length);
|
||||
if (status < 0) {
|
||||
PR_Free(rotated_line);
|
||||
return status;
|
||||
}
|
||||
|
||||
line = rotated_line;
|
||||
} else {
|
||||
line = original_line;
|
||||
}
|
||||
|
||||
// Now convert to the canonical charset, if desired.
|
||||
|
@ -435,5 +449,6 @@ static int MimeInlineText_rotate_convert_and_parse_line(char* line,
|
|||
} else
|
||||
status = obj->clazz->parse_line(line, length, obj);
|
||||
|
||||
PR_FREEIF(rotated_line);
|
||||
return status;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче