Skip to contentSkip to conversation

'make install' may overwrite existing directories

BUG Alejandro Colomar 1 participant 1 message Oct 20, 2022

lore
Share & tools
lore
#0 lore raw

Hi,

The project Makefile defines the install target as:

$ sed -n '3236,3245p' Makefile

install: all

	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
	$(INSTALL) $(INSTALL_STRIP) $(PROGRAMS) 
'$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
	$(INSTALL) $(SCRIPTS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
	$(INSTALL) $(INSTALL_STRIP) $(install_bindir_xprograms) 
'$(DESTDIR_SQ)$(bindir_SQ)'
	$(INSTALL) $(BINDIR_PROGRAMS_NO_X) '$(DESTDIR_SQ)$(bindir_SQ)'

Notice that the directories are being installed even if they already exist. This may be problematic in case the existing directories have a different mode, or have SELinux security contexts, or any other characteristic that install(1) would overwrite.

A similar bug report in an NGINX project can be found here:

<https://github.com/nginx/unit/issues/769>

The two solutions available are:

- Make the install target be a dummy target that depends on the files being installed, and write proper make(1) rules for those targets. This would be preferred. You can check the Linux man-pages Makefile for an implementation of the 'install' target that does this.

- test(1) if the directory exists before actually creating it. This is a simple workaround.

Cheers,

Alex

Signature · 1 line
<http://www.alejandro-colomar.es/>