Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
b70b9bfe
...
b70b9bfef7286da3554de9187149e4dfbb990d53
authored
2004-07-01 09:07:04 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
(rfc2047_decode): Fixed buffer handling
1 parent
1825096b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
13 deletions
mailbox/rfc2047.c
mailbox/rfc2047.c
View file @
b70b9bf
...
...
@@ -28,6 +28,18 @@
#include <mailutils/errno.h>
#include <mailutils/mutil.h>
static
int
realloc_buffer
(
char
**
bufp
,
size_t
*
bufsizep
,
size_t
incr
)
{
size_t
newsize
=
*
bufsizep
+
incr
;
char
*
newp
=
realloc
(
*
bufp
,
newsize
);
if
(
newp
==
NULL
)
return
1
;
*
bufp
=
newp
;
*
bufsizep
=
newsize
;
return
0
;
}
int
rfc2047_decode
(
const
char
*
tocode
,
const
char
*
input
,
char
**
ptostr
)
{
...
...
@@ -38,6 +50,22 @@ rfc2047_decode (const char *tocode, const char *input, char **ptostr)
size_t
bufsize
;
size_t
bufpos
;
size_t
run_count
=
0
;
#define BUFINC 128
#define CHKBUF(count) do { \
if (bufpos+count >= bufsize) \
{ \
size_t s = bufpos + count - bufsize; \
if (s < BUFINC) \
s = BUFINC; \
if (realloc_buffer (&buffer, &bufsize, s)) \
{ \
free (tmpcopy); \
free (buffer); \
return ENOMEM; \
} \
} \
} while (0)
if
(
!
tocode
||
!
input
)
return
EINVAL
;
...
...
@@ -124,10 +152,9 @@ rfc2047_decode (const char *tocode, const char *input, char **ptostr)
while
(
stream_sequential_read
(
filter
,
buffer
+
bufpos
,
bufsize
-
bufpos
,
&
nbytes
)
==
0
&&
nbytes
)
{
bufpos
+=
nbytes
;
}
&
nbytes
)
==
0
&&
nbytes
)
bufpos
+=
nbytes
;
stream_close
(
filter
);
stream_destroy
(
&
filter
,
stream_get_owner
(
filter
));
...
...
@@ -147,30 +174,31 @@ rfc2047_decode (const char *tocode, const char *input, char **ptostr)
{
if
(
--
run_count
)
{
CHKBUF
(
run_count
);
memcpy
(
buffer
+
bufpos
,
fromstr
-
run_count
,
run_count
);
bufpos
+=
run_count
;
run_count
=
0
;
}
CHKBUF
(
1
);
buffer
[
bufpos
++
]
=
*
fromstr
++
;
}
}
else
buffer
[
bufpos
++
]
=
*
fromstr
++
;
{
CHKBUF
(
1
);
buffer
[
bufpos
++
]
=
*
fromstr
++
;
}
}
if
(
*
fromstr
)
{
size_t
len
=
strlen
(
fromstr
);
if
(
bufpos
+
len
+
1
>
bufsize
)
/* just in case */
status
=
MU_ERR_BAD_2047_INPUT
;
else
{
memcpy
(
buffer
+
bufpos
,
fromstr
,
strlen
(
fromstr
));
bufpos
+=
strlen
(
fromstr
);
}
CHKBUF
(
len
);
memcpy
(
buffer
+
bufpos
,
fromstr
,
strlen
(
fromstr
));
bufpos
+=
strlen
(
fromstr
);
}
CHKBUF
(
1
);
buffer
[
bufpos
++
]
=
0
;
free
(
tmpcopy
);
...
...
Please
register
or
sign in
to post a comment