Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: ‘strncpy’ specified bound 256 equals destination size [-Werror=stringop-truncation] 917 | strncpy(space->addr_name, node, sizeof(space->addr_name)); #171

Open
BRNAREA opened this issue Dec 26, 2024 · 0 comments

Comments

@BRNAREA
Copy link

BRNAREA commented Dec 26, 2024

When compiling the proxychains version 4.4.0 source code, a misleading-indentation compilation warning is triggered due to the lack of braces ({}) around an if statement block. This causes the code to appear logically incorrect and results in compilation failures when warning flags are enabled, such as with the -Werror flag.

Steps to Reproduce:

OS: Debian GNU/Linux 12 (bookworm) x86_64
Kernel: 6.1.0-28-amd64
DE: Plasma 5

  1. Download and extract the proxychains version 4.4.0 source code.
  2. Run the configure command.
  3. Run the make command.
  4. The error will occur due to incorrect indentation in the file src/core.c.
~/Downloads/proxychains-proxychains-4.4.0 
> make
cc -MD -Wall -O2 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror   -DLIB_DIR=\"/usr/local/lib\" -DINSTALL_PREFIX=\"/usr/local\" -DDLL_NAME=\"libproxychains4.so\" -DSYSCONFDIR=\"/usr/local/etc\"  -fPIC -c -o src/core.o src/core.c
src/core.c: In function ‘proxy_gethostbyname’:
src/core.c:832:9: error: ‘strncpy’ specified bound 8192 equals destination size [-Werror=stringop-truncation]
  832 |         strncpy(data->addr_name, name, sizeof(data->addr_name));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/core.c: In function ‘proxy_getaddrinfo’:
src/core.c:917:17: error: ‘strncpy’ specified bound 256 equals destination size [-Werror=stringop-truncation]
  917 |                 strncpy(space->addr_name, node, sizeof(space->addr_name));
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:65: src/core.o] Erro 1

Solution:

  1. In src/core.c line 832 after "strncpy(data->addr_name, name, sizeof(data->addr_name) - 1);" add the following code:

data->addr_name[sizeof(data->addr_name) - 1] = '\0';

its look like this:
image

  1. Also in line 917 (core.c) i have to check the end of string with:
if(node) {                                                         
                strncpy(space->addr_name, node, sizeof(space->addr_name)); 
                space->addr_name[sizeof(space->addr_name) - 1] = '\0'; 
}

its looks like:
image

  1. Recompile the code and done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant