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

snprintf() truncates --rundir in plutomain.c #428

Closed
markdgray opened this issue Mar 30, 2021 · 3 comments
Closed

snprintf() truncates --rundir in plutomain.c #428

markdgray opened this issue Mar 30, 2021 · 3 comments

Comments

@markdgray
Copy link

markdgray commented Mar 30, 2021

mkdir /tmp/ipsec.d && ipsec initnss --nssdir /tmp/ipsec.d
mkdir /tmp/somelongpathxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
sudo ipsec pluto  --nssdir /tmp/ipsec.d --rundir/tmp/somelongpathxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
ls -al /tmp/some*

This returns:

srwx------. 1 root   root  0 Mar 30 13:12 /tmp/somelongpathxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

/tmp/somelongpathxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
total 12

The socket is not placed in the directory and is named incorrectly.

Even more confusing is when the length of rundir is 107 (sizeof(ctl_addr.sun_path)) characters (which was my case)

mkdir /tmp/ipsec.d && ipsec initnss --nssdir /tmp/ipsec.d
mkdir 
/tmp/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
sudo ipsec pluto  --nssdir /tmp/ipsec.d --rundir /tmp/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

This returns the following which is really confusing!

pluto: FATAL: unable to create lock file "/tmp/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/" (21 Is a directory)

Both are due to the following line in which the return code of snprintf() is not checked for truncation:

if (snprintf(pluto_lock, sizeof(pluto_lock),

@letoams
Copy link
Member

letoams commented Mar 30, 2021 via email

@markdgray
Copy link
Author

It was in a test environment. This is low priority as we can work around it but I wanted to raise it.

@cagney
Copy link
Collaborator

cagney commented Apr 5, 2021

I suspect ctl_addr.sun_path can be replaced by a simple string pointer and alloc_printf()

Rishabh-Kumar-07 pushed a commit to Rishabh-Kumar-07/libreswan that referenced this issue Aug 20, 2021
Rishabh-Kumar-07 pushed a commit to Rishabh-Kumar-07/libreswan that referenced this issue Aug 21, 2021
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

3 participants