Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
4a1e05de
Commit
4a1e05de
authored
21 years ago
by
Roger Dingledine
Browse files
Options
Downloads
Patches
Plain Diff
betcha didn't know strncpy could leave an unterminated string
svn:r949
parent
aba237e3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/or/dirserv.c
+2
-0
2 additions, 0 deletions
src/or/dirserv.c
src/or/dns.c
+6
-1
6 additions, 1 deletion
src/or/dns.c
with
8 additions
and
1 deletion
src/or/dirserv.c
+
2
−
0
View file @
4a1e05de
...
...
@@ -376,6 +376,7 @@ dirserv_dump_directory_to_string(char *s, int maxlen,
for
(
i
=
0
;
i
<
n_descriptors
;
++
i
)
{
strncat
(
cp
,
descriptor_list
[
i
]
->
descriptor
,
descriptor_list
[
i
]
->
desc_len
);
/* XXX Nick: do strncat and friends null-terminate? man page is ambiguous. */
cp
+=
descriptor_list
[
i
]
->
desc_len
;
assert
(
!*
cp
);
}
...
...
@@ -400,6 +401,7 @@ dirserv_dump_directory_to_string(char *s, int maxlen,
((
int
)
digest
[
2
])
&
0xff
,((
int
)
digest
[
3
])
&
0xff
);
strncpy
(
cp
,
"-----BEGIN SIGNATURE-----
\n
"
,
maxlen
-
i
);
cp
[
maxlen
-
i
-
1
]
=
0
;
i
=
strlen
(
s
);
cp
=
s
+
i
;
...
...
This diff is collapsed.
Click to expand it.
src/or/dns.c
+
6
−
1
View file @
4a1e05de
...
...
@@ -100,6 +100,7 @@ uint32_t dns_lookup(const char *address) {
}
strncpy(search.address, address, MAX_ADDRESSLEN);
search.address[MAX_ADDRESSLEN-1] = 0;
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
if(resolve) { /* it's there */
if(resolve->state == CACHE_STATE_VALID) {
...
...
@@ -118,7 +119,7 @@ uint32_t dns_lookup(const char *address) {
}
#endif
/* See if we have a
n addr
for 'exitconn->address'. if so,
/* See if we have a
cache entry
for 'exitconn->address'. if so,
* if resolve valid, put it into exitconn->addr and return 1.
* If resolve failed, return -1.
*
...
...
@@ -140,6 +141,7 @@ int dns_resolve(connection_t *exitconn) {
/* now check the tree to see if 'address' is already there. */
strncpy
(
search
.
address
,
exitconn
->
address
,
MAX_ADDRESSLEN
);
search
.
address
[
MAX_ADDRESSLEN
-
1
]
=
0
;
resolve
=
SPLAY_FIND
(
cache_tree
,
&
cache_root
,
&
search
);
if
(
resolve
)
{
/* already there */
switch
(
resolve
->
state
)
{
...
...
@@ -167,6 +169,7 @@ int dns_resolve(connection_t *exitconn) {
resolve
->
state
=
CACHE_STATE_PENDING
;
resolve
->
expire
=
now
+
MAX_DNS_ENTRY_AGE
;
strncpy
(
resolve
->
address
,
exitconn
->
address
,
MAX_ADDRESSLEN
);
resolve
->
address
[
MAX_ADDRESSLEN
-
1
]
=
0
;
/* add us to the pending list */
pending_connection
=
tor_malloc
(
sizeof
(
struct
pending_connection_t
));
...
...
@@ -226,6 +229,7 @@ void dns_cancel_pending_resolve(char *address, connection_t *onlyconn) {
struct
cached_resolve
*
resolve
,
*
tmp
;
strncpy
(
search
.
address
,
address
,
MAX_ADDRESSLEN
);
search
.
address
[
MAX_ADDRESSLEN
-
1
]
=
0
;
resolve
=
SPLAY_FIND
(
cache_tree
,
&
cache_root
,
&
search
);
if
(
!
resolve
)
{
...
...
@@ -299,6 +303,7 @@ static void dns_found_answer(char *address, uint32_t addr) {
struct
cached_resolve
*
resolve
;
strncpy
(
search
.
address
,
address
,
MAX_ADDRESSLEN
);
search
.
address
[
MAX_ADDRESSLEN
-
1
]
=
0
;
resolve
=
SPLAY_FIND
(
cache_tree
,
&
cache_root
,
&
search
);
if
(
!
resolve
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment