#21 warning: ‘strncpy’ output truncated before terminating nul copying 3 bytes from a string of the same length
Closed: fixed 5 years ago Opened 5 years ago by emaldonado.

The [-Wstringop-truncation] compiler flag triggers this. From the build output file we have:

gcc -o Linux4.17_x86_64_glibc_PTH_64_DBG.OBJ/pathsub.o -c -g -D_POSIX_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -fPIC -DLINUX2_1  -Wall -Werror-implicit-function-declaration -Wno-switch -pipe -DLINUX -Dlinux -DHAVE_STRERROR -DXP_UNIX -DDEBUG -UNDEBUG -DDEBUG_emaldonado -D_REENTRANT -DUSE_UTIL_DIRECTLY -I../../../dist/Linux4.17_x86_64_glibc_PTH_64_DBG.OBJ/include -I../../../dist/public/coreconf -I../../../dist/private/coreconf  pathsub.c
pathsub.c: In function ‘reversepath’:
pathsub.c:217:6: warning: ‘strncpy’ output truncated before terminating nul copying 3 bytes from a string of the same length [-Wstringop-truncation]
      strncpy(cp, "../", 3);
      ^~~~~~~~~~~~~~~~~~~~~
gcc -o Linux4.17_x86_64_glibc_PTH_64_DBG.OBJ/nsinstall -g -D_POSIX_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -fPIC -DLINUX2_1  -Wall -Werror-implicit-function-declaration -Wno-switch -pipe -DLINUX -Dlinux -DHAVE_STRERROR -DXP_UNIX -DDEBUG -UNDEBUG -DDEBUG_emaldonado -D_REENTRANT -DUSE_UTIL_DIRECTLY -I../../../dist/Linux4.17_x86_64_glibc_PTH_64_DBG.OBJ/include -I../../../dist/public/coreconf -I../../../dist/private/coreconf  Linux4.17_x86_64_glibc_PTH_64_DBG.OBJ/nsinstall.o Linux4.17_x86_64_glibc_PTH_64_DBG.OBJ/pathsub.o    -lpthread  -ldl -lc
true -m 775 Linux4.17_x86_64_glibc_PTH_64_DBG.OBJ/nsinstall ../../../dist/Linux4.17_x86_64_glibc_PTH_64_DBG.OBJ/bin
make[2]: Leaving directory '/home/emaldonado/COMPILER_WARNING/jss/coreconf/nsinstall'

Here is the relevant code from ./coreconf/nsinstall/pathsub.c

    } else {
        cp -= 3;
        strncpy(cp, "../", 3); <--- the offending line
        xchdir(buf);
    }

Two simple ways to fix this:

Option 1:

    } else {
        cp -= 3;
        const char *src = "../";
        strncpy(cp, src, srtlen(src)); <--- the offedning line
        xchdir(buf);
    }

Option 2:

    } else {
        cp -= 3;
        const char *src = "../";
        mencpy(cp, "../", 3); <--- the offedning line
        xchdir(buf);
    }

I prefer the Option 2 as being simpler. Preferences anyone?


I meant to type memcpy(cp, "../", 3);

@emaldonado the simpler fix is fine. Do you want to commit it and create the pull request on GitHub, or would you like one of the PKI devs to do it?

Metadata Update from @ftweedal:
- Custom field component adjusted to None
- Custom field feature adjusted to None
- Custom field origin adjusted to None
- Custom field proposedmilestone adjusted to None
- Custom field proposedpriority adjusted to None
- Custom field reviewer adjusted to None
- Custom field type adjusted to None
- Custom field version adjusted to None

5 years ago

(Updated comment to use Markdown formatting).

Upstream PR submitted by @emaldonado is jss pr#24.

This is fixed by jss pr#24. It is in master as 18cc00.

Metadata Update from @cipherboy:
- Issue assigned to cipherboy

5 years ago

Metadata Update from @cipherboy:
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

5 years ago

Login to comment on this ticket.

Metadata
Attachments 1