Bladeren bron

Merge pull request #94 from lubosz/fix-overflow

rift: Fix buffer overflow
TheOnlyJoey 8 jaren geleden
bovenliggende
commit
fb80db7371
1 gewijzigde bestanden met toevoegingen van 9 en 6 verwijderingen
  1. 9 6
      src/drv_oculus_rift/rift.c

+ 9 - 6
src/drv_oculus_rift/rift.c

@@ -212,12 +212,12 @@ static void close_device(ohmd_device* device)
 
 static char* _hid_to_unix_path(char* path)
 {
-	char bus [4];
-	char dev [4];
+	char bus [5];
+	char dev [5];
 	char *result = malloc( sizeof(char) * ( 20 + 1 ) );
 
-	sprintf (bus, "%.*s\n", 4, path);
-	sprintf (dev, "%.*s\n", 4, path + 5);
+	sprintf (bus, "%.*s", 4, path);
+	sprintf (dev, "%.*s", 4, path + 5);
 
 	sprintf (result, "/dev/bus/usb/%03d/%03d",
 		(int)strtol(bus, NULL, 16),
@@ -225,6 +225,8 @@ static char* _hid_to_unix_path(char* path)
 	return result;
 }
 
+#define UDEV_WIKI_URL "https://github.com/OpenHMD/OpenHMD/wiki/Udev-rules-list"
+
 static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 {
 	rift_priv* priv = ohmd_alloc(driver->ctx, sizeof(rift_priv));
@@ -240,8 +242,9 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 
 	if(!priv->handle) {
 		char* path = _hid_to_unix_path(desc->path);
-		ohmd_set_error(driver->ctx, "Could not open %s. "
-		                            "Check your rights.", path);
+		ohmd_set_error(driver->ctx, "Could not open %s.\n"
+		                            "Check your rights: "
+		                            UDEV_WIKI_URL, path);
 		free(path);
 		goto cleanup;
 	}