Forgot to use realpath()

This commit is contained in:
Kovid Goyal 2011-11-03 08:33:19 +05:30
parent d43d661830
commit 99e686faf5
2 changed files with 25 additions and 2 deletions

View File

@ -1,3 +1,4 @@
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@ -36,17 +37,35 @@ void ensure_root() {
}
int check_args(const char *dev, const char *mp) {
char buffer[PATH_MAX+1];
if (dev == NULL || strlen(dev) < strlen(DEV) || mp == NULL || strlen(mp) < strlen(MEDIA)) {
fprintf(stderr, "Invalid arguments\n");
return False;
}
if (strncmp(MEDIA, mp, strlen("MEDIA")) != 0) {
if (exists(mp)) {
if (realpath(mp, buffer) == NULL) {
fprintf(stderr, "Unable to resolve mount path\n");
return False;
}
if (strncmp(MEDIA, buffer, strlen(MEDIA)) != 0) {
fprintf(stderr, "Trying to operate on a mount point not under /media is not allowed\n");
return False;
}
}
if (strncmp(MEDIA, mp, strlen(MEDIA)) != 0) {
fprintf(stderr, "Trying to operate on a mount point not under /media is not allowed\n");
return False;
}
if (strncmp(DEV, dev, strlen(DEV)) != 0) {
if (realpath(dev, buffer) == NULL) {
fprintf(stderr, "Unable to resolve dev path\n");
return False;
}
if (strncmp(DEV, buffer, strlen(DEV)) != 0) {
fprintf(stderr, "Trying to operate on a dev node not under /dev\n");
return False;
}

View File

@ -194,4 +194,8 @@ class SpooledTemporaryFile(tempfile.SpooledTemporaryFile):
tempfile.SpooledTemporaryFile.__init__(self, max_size=max_size, suffix=suffix,
prefix=prefix, dir=dir, mode=mode, bufsize=bufsize)
def better_mktemp(*args, **kwargs):
fd, path = tempfile.mkstemp(*args, **kwargs)
os.close(fd)
return path