If the filename passed to open_file was larger than MAXPATHLEN-5,
then we'd overflow the oldName buffer when creating the backup
filename. Fix the overflow by using a malloc'd buffer instead.
Caught by coverity (#985767)
Reviewed-on: http://gerrit.openafs.org/9448
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
(cherry picked from commit
b0b3def56c15161df28059e270f0360c31241217)
Change-Id: I3993de8e4372c30d35e6e675042511f85ba9d014
Reviewed-on: http://gerrit.openafs.org/11062
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
open_file(const char *fileName)
{
int tempfd, flags;
- char oldName[MAXPATHLEN];
+ char *oldName;
#ifndef AFS_NT40_ENV
struct stat statbuf;
} else
#endif
{
- strcpy(oldName, fileName);
- strcat(oldName, ".old");
+ afs_asprintf(&oldName, "%s.old", fileName);
+ if (oldName == NULL) {
+ printf("Warning: Unable to create backup filename. Auditing ignored\n");
+ return 1;
+ }
renamefile(fileName, oldName);
flags = O_WRONLY | O_TRUNC | O_CREAT;
+ free(oldName);
}
tempfd = open(fileName, flags, 0666);
if (tempfd > -1) {