]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/Deluge/DelugeManagerP.nc
Check the image number against the DELUGE_NUM_VOLUMES. The bug was reported by David...
[tinyos-2.x.git] / tos / lib / net / Deluge / DelugeManagerP.nc
index d7146af91a941e32e2d3a7c6e866e81b2844bc3d..342d8ca21cfc6462209e83d9fa38aa2ec255282d 100644 (file)
@@ -55,6 +55,12 @@ implementation
 
   message_t serialMsg;
   DelugeCmd delugeCmd;
+  uint8_t imgNum2volumeId[] = {
+    VOLUME_GOLDENIMAGE,
+    VOLUME_DELUGE1,
+    VOLUME_DELUGE2,
+    VOLUME_DELUGE3
+  };
 
   void sendReply(error_t error)
   {
@@ -84,14 +90,21 @@ implementation
       break;
     case DELUGE_CMD_ONLY_DISSEMINATE:
     case DELUGE_CMD_DISSEMINATE_AND_REPROGRAM:
-      if (call Resource.immediateRequest() == SUCCESS) {
-       call DelugeMetadata.read(request->imgNum);
+      if (request->imgNum < DELUGE_NUM_VOLUMES &&
+         (call Resource.isOwner() || 
+          call Resource.immediateRequest() == SUCCESS)) {
+       call DelugeMetadata.read(imgNum2volumeId[request->imgNum]);
       } else {
        sendReply(FAIL);
       }
       break;
     case DELUGE_CMD_REPROGRAM:
+      if (!(request->imgNum < DELUGE_NUM_VOLUMES)) {
+       sendReply(FAIL);
+       break;
+      }
     case DELUGE_CMD_REBOOT:
+      delugeCmd.imgNum = imgNum2volumeId[request->imgNum];
       call DelayTimer.startOneShot(1024);
       sendReply(SUCCESS);
       break;