mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
calibre-mount-helper: Validate dev arg as well as mount
This commit is contained in:
parent
8b21b4a4ad
commit
eb2a40ffef
@ -33,6 +33,25 @@ void ensure_root() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int check_args(const char *dev, const char *mp) {
|
||||||
|
if (dev == NULL || strlen(dev) < strlen("/dev/") || mp == NULL || strlen(mp) < strlen("/media/")) {
|
||||||
|
fprintf(stderr, "Invalid arguments\n");
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp("/media/", mp, 6) != 0) {
|
||||||
|
fprintf(stderr, "Trying to operate on a mount point not under /media is not allowed\n");
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp("/dev/", dev, 5) != 0) {
|
||||||
|
fprintf(stderr, "Trying to operate on a dev node not under /dev\n");
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
|
||||||
int do_mount(const char *dev, const char *mp) {
|
int do_mount(const char *dev, const char *mp) {
|
||||||
char options[1000], marker[2000];
|
char options[1000], marker[2000];
|
||||||
#ifdef __NetBSD__
|
#ifdef __NetBSD__
|
||||||
@ -45,11 +64,6 @@ int do_mount(const char *dev, const char *mp) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp("/usr", mp, 4) == 0 || strncmp("/bin", mp, 4) == 0 || strncmp("/sbin", mp, 5) == 0) {
|
|
||||||
fprintf(stderr, "Trying to mount to a mount point under /usr, /bin, /sbin is not allowed\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!exists(mp)) {
|
if (!exists(mp)) {
|
||||||
if (mkdir(mp, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) != 0) {
|
if (mkdir(mp, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) != 0) {
|
||||||
errsv = errno;
|
errsv = errno;
|
||||||
@ -226,6 +240,8 @@ int main(int argc, char** argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!check_args(dev, mp)) exit(EXIT_FAILURE);
|
||||||
|
|
||||||
if (strncmp(action, "mount", 5) == 0) {
|
if (strncmp(action, "mount", 5) == 0) {
|
||||||
status = do_mount(dev, mp);
|
status = do_mount(dev, mp);
|
||||||
} else if (strncmp(action, "eject", 5) == 0) {
|
} else if (strncmp(action, "eject", 5) == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user