Potential off by one issues 0.7

Open
#76 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
c, cpp
Domain
backend

Research direction

Start by checking the compiler warnings in the listed locations: ncrack_psql.cc:195, ncrack_winrm.cc:1001 and 1382, ncrack_mssql.cc:509, nsock_connect.c:364, and ncrack_resume.cc:477. Compare each buffer’s declared size with the reads and writes, then run the project’s relevant build or tests to verify any fixes; done means the reported warnings are resolved without breaking those paths.

Written by the indexing model from the issue text.

Description

Hello,
during compilation of the 0.7 I have noticed couple of potential off-by-one issues which might be causing instability of ncrack.
https://kojipkgs.fedoraproject.org//work/tasks/1387/43251387/build.log

ncrack_psql.cc: In function 'void ncrack_psql(nsock_pool, Connection*)':
ncrack_psql.cc:195:36: warning: array subscript 35 is outside array bounds of 'char [35]' [-Warray-bounds]
195 | buf[MD5_DIGEST_LENGTH * 2 + 3] = '\0';
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
ncrack_psql.cc:295:8: note: while referencing 'response_hex'
295 | char response_hex[MD5_DIGEST_LENGTH *2 + 3];
| ^~~~~~~~~~~~

In function 'void rand_str(char*, size_t)',
inlined from 'void winrm_negotiate(nsock_pool, Connection*)' at ncrack_winrm.cc:1001:21:
ncrack_winrm.cc:1382:11: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
1382 | dest = '\0';
| ~~~~~~^~~~~~
ncrack_winrm.cc: In function 'void winrm_negotiate(nsock_pool, Connection
)':
ncrack_winrm.cc:994:18: note: at offset 8 to object 'entropy' with size 8 declared here
994 | char entropy[8];
| ^~~~~~~

ncrack_mssql.cc: In function 'void ncrack_mssql(nsock_pool, Connection*)':
ncrack_mssql.cc:509:63: warning: array subscript 2 is outside array bounds of 'unsigned char [1]' [-Warray-bounds]
509 | memcpy(tmp + 179 + 30 + 1 + 1 + 1 + 30 + 223, &len_pass + 2, 1);
| ~~~~~~~~~~^~~
ncrack_mssql.cc:160:28: note: while referencing 'len_pass'
160 | unsigned char len_login, len_pass;
| ^~~~~~~~
In file included from /usr/include/string.h:495,
from ../nbase/nbase.h:203,
from ../ncrack.h:161,
from ncrack_mssql.cc:131:
In function 'void* memcpy(void*, const void*, size_t)',
inlined from 'void ncrack_mssql(nsock_pool, Connection*)' at ncrack_mssql.cc:509:13:
/usr/include/bits/string_fortified.h:34:33: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' reading 1 byte from a region of size 0 [-Wstringop-overflow=]
34 | return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /usr/include/string.h:495,
from /usr/include/sys/un.h:37,
from ../include/nsock.h:82,
from nsock_connect.c:57:
In function 'strncpy',
inlined from 'nsock_connect_tcp_socks4a' at nsock_connect.c:364:3:
/usr/include/bits/string_fortified.h:106:10: warning: '__builtin_strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nsock_connect.c: In function 'nsock_connect_tcp_socks4a':
nsock_connect.c:364:3: note: length computed here
364 | strncpy(nsi->hostname, targetname, strlen(targetname));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /usr/include/string.h:495,
from nbase/nbase.h:203,
from ncrack.h:161,
from ncrack_resume.h:132,
from ncrack_resume.cc:132:
In function 'char* strncpy(char*, const char*, size_t)',
inlined from 'int ncrack_resume(char*, int*, char***)' at ncrack_resume.cc:477:10:
/usr/include/bits/string_fortified.h:106:34: warning: 'char* __builtin_strncpy(char*, const char*, long unsigned int)' output truncated before terminating nul copying 7 bytes from a string of the same length [-Wstringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dominant language
C
Stars
1.2k
Forks
275
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nmap/ncrack

All issues in nmap/ncrack

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.