grammar updates
[mono.git] / mono / metadata / process.c
index 742b4541943ba056143fe14f0a7a70101b955118..99494210bf73b8c7856dc2b77840af19ffdba000 100644 (file)
@@ -189,11 +189,14 @@ typedef struct {
 static gpointer process_get_versioninfo_block (gpointer data,
                                               version_data *block)
 {
-       block->data_len=*(((guint16 *)data)++);
-       block->value_len=*(((guint16 *)data)++);
+       block->data_len=*((guint16 *)data);
+       data = (char *)data + sizeof(guint16);
+       block->value_len=*((guint16 *)data);
+       data = (char *)data + sizeof(guint16);
 
        /* No idea what the type is supposed to indicate */
-       block->type=*(((guint16 *)data)++);
+       block->type=*((guint16 *)data);
+       data = (char *)data + sizeof(guint16);
        block->key=((gunichar2 *)data);
 
        /* skip over the key (including the terminator) */
@@ -223,7 +226,11 @@ static gpointer process_read_var_block (MonoObject *filever, gpointer data_ptr,
        return(data_ptr);
 }
 
-/* Returns a pointer to the byte following the String block */
+/* Returns a pointer to the byte following the String block, or NULL
+ * if the data read hits padding.  We can't recover from this because
+ * the data length does not include padding bytes, so it's not
+ * possible to just return the start position + length.
+ */
 static gpointer process_read_string_block (MonoObject *filever,
                                           gpointer data_ptr,
                                           guint16 data_len,
@@ -301,6 +308,17 @@ static gpointer process_read_string_block (MonoObject *filever,
                data_ptr=(gpointer)(((unsigned)data_ptr+3) & (~3));
 
                data_ptr=process_get_versioninfo_block (data_ptr, &block);
+               if(block.data_len==0) {
+                       /* We must have hit padding, so give up
+                        * processing now
+                        */
+#ifdef DEBUG
+                       g_message (G_GNUC_PRETTY_FUNCTION
+                                  ": Hit 0-length block, giving up");
+#endif
+                       return(NULL);
+               }
+               
                string_len=string_len+block.data_len;
                value=(gunichar2 *)data_ptr;
                /* Skip over the value */
@@ -354,7 +372,11 @@ static gpointer process_read_string_block (MonoObject *filever,
        return(data_ptr);
 }
 
-/* returns a pointer to the byte following the Stringtable block */
+/* returns a pointer to the byte following the Stringtable block, or
+ * NULL if the data read hits padding.  We can't recover from this
+ * because the data length does not include padding bytes, so it's not
+ * possible to just return the start position + length
+ */
 static gpointer process_read_stringtable_block (MonoObject *filever,
                                                gpointer data_ptr,
                                                guint16 data_len)
@@ -382,6 +404,16 @@ static gpointer process_read_stringtable_block (MonoObject *filever,
                data_ptr=(gpointer)(((unsigned)data_ptr+3) & (~3));
 
                data_ptr=process_get_versioninfo_block (data_ptr, &block);
+               if(block.data_len==0) {
+                       /* We must have hit padding, so give up
+                        * processing now
+                        */
+#ifdef DEBUG
+                       g_message (G_GNUC_PRETTY_FUNCTION
+                                  ": Hit 0-length block, giving up");
+#endif
+                       return(NULL);
+               }
                string_len=string_len+block.data_len;
        
                if(!memcmp (block.key, &uni_key, unicode_bytes (block.key)) ||
@@ -401,6 +433,14 @@ static gpointer process_read_stringtable_block (MonoObject *filever,
                                                            block.data_len,
                                                            FALSE);
                }
+
+               if(data_ptr==NULL) {
+                       /* Child block hit padding */
+#ifdef DEBUG
+                       g_message (G_GNUC_PRETTY_FUNCTION ": Child block hit 0-length block, giving up");
+#endif
+                       return(NULL);
+               }
        }
                
        return(data_ptr);
@@ -509,7 +549,8 @@ static void process_get_fileversion (MonoObject *filever, MonoImage *image)
                return;
        }
 
-       ffi=(((VS_FIXEDFILEINFO *)data_ptr)++);
+       ffi=((VS_FIXEDFILEINFO *)data_ptr);
+       data_ptr = (char *)data_ptr + sizeof(VS_FIXEDFILEINFO);
        if((ffi->dwSignature!=VS_FFI_SIGNATURE) ||
           (ffi->dwStrucVersion!=VS_FFI_STRUCVERSION)) {
 #ifdef DEBUG
@@ -531,6 +572,17 @@ static void process_get_fileversion (MonoObject *filever, MonoImage *image)
                data_ptr=(gpointer)(((unsigned)data_ptr+3) & (~3));
 
                data_ptr=process_get_versioninfo_block (data_ptr, &block);
+               if(block.data_len==0) {
+                       /* We must have hit padding, so give up
+                        * processing now
+                        */
+#ifdef DEBUG
+                       g_message (G_GNUC_PRETTY_FUNCTION
+                                  ": Hit 0-length block, giving up");
+#endif
+                       return;
+               }
+               
                data_len=data_len-block.data_len;
 
                if(!memcmp (block.key, &var_key, unicode_bytes (block.key))) {
@@ -547,6 +599,14 @@ static void process_get_fileversion (MonoObject *filever, MonoImage *image)
                        return;
 #endif
                }
+
+               if(data_ptr==NULL) {
+                       /* Child block hit padding */
+#ifdef DEBUG
+                       g_message (G_GNUC_PRETTY_FUNCTION ": Child block hit 0-length block, giving up");
+#endif
+                       return;
+               }
        }
 }
 
@@ -693,7 +753,7 @@ MonoBoolean ves_icall_System_Diagnostics_Process_Start_internal (MonoString *cmd
        
        ret=CreateProcess (NULL, mono_string_chars (cmd), NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT, NULL, dir, &startinfo, &procinfo);
 
-       if(ret==TRUE) {
+       if(ret) {
                process_info->process_handle=procinfo.hProcess;
                process_info->thread_handle=procinfo.hThread;
                process_info->pid=procinfo.dwProcessId;